javascript - Get current index of an item with Object.entries().map - Stack Overflow

I know it is probably a silly question but I can' find an answer by myself, so..How can I get curr

I know it is probably a silly question but I can' find an answer by myself, so..

How can I get current index with this construction .map(([key, value])?

to access it inside the map function bellow

     return (
        <Fragment>
            {Object.entries(props.values).map(([key, value]) => {
                return (
                    <Button
                        key={key}
                        value={value}                      
                    />
                );
            })}
        </Fragment>
     );

I know it is probably a silly question but I can' find an answer by myself, so..

How can I get current index with this construction .map(([key, value])?

to access it inside the map function bellow

     return (
        <Fragment>
            {Object.entries(props.values).map(([key, value]) => {
                return (
                    <Button
                        key={key}
                        value={value}                      
                    />
                );
            })}
        </Fragment>
     );
Share Improve this question asked May 6, 2020 at 17:06 AndrewAndrew 7951 gold badge10 silver badges23 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You can obtain an index from callback in map

 return (
    <Fragment>
        {Object.entries(props.values).map(([key, value], index) => {
            return (
                <Button
                    key={key}
                    value={value}                      
                />
            );
        })}
    </Fragment>
 );

Please check https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745398825a4626006.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信