Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

object key map javascript

const object = {1: 'a', 2: 'b', 3: 'c'};

// convert to the array keys 
let array =Object.keys(object);

// index is based on zero
let newArray = array.map((item, index) => {
    console.log(`Item => "${item}", Index => ${index}`);
    return item * 2;
});

// newArray will be [2, 4, 6]
Source by tutorialmeta.com #
 
PREVIOUS NEXT
Tagged: #object #key #map #javascript
ADD COMMENT
Topic
Name
8+6 =