Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keyBy not support index #5795

Open
wongest opened this issue Dec 27, 2023 · 2 comments
Open

keyBy not support index #5795

wongest opened this issue Dec 27, 2023 · 2 comments

Comments

@wongest
Copy link

wongest commented Dec 27, 2023

VERSION 4.17.21

Hope to support the index of the iterator

Example

keyBy(['a', 'b'], (_, index) => index);

Expected Result

{
  0: 'a',
  1: 'b',
}

Actual Result

{
  undefined: 'b',
}
@vincediegane
Copy link

vincediegane commented Dec 28, 2023

You can try with this for the time being.

Example

const array1 = ['a', 'b'];

const array2 = [
  { 'dir': 'left', 'code': 97 },
  { 'dir': 'right', 'code': 100 }
];

console.log( keyBy(array1, _ => array1.indexOf(_)) );

console.log( keyBy(array2, _ => array2.indexOf(_)) );

Actual Result

 {
   0: 'a',
   1: 'b'
 }
 
 { 
   0: { dir: 'left', code: 97 },
   1: { dir: 'right', code: 100 }
 }

@sid0-0
Copy link

sid0-0 commented Jan 2, 2024

Raised a pull request (#5798).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants