Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

how to add id in array javascript

let data = [{
    color: "red",
    value: "#f00"
}, {
    color: "green",
    value: "#0f0"
}, {
    color: "blue",
    value: "#00f"
}, {
    color: "cyan",
    value: "#0ff"
}, {
    color: "magenta",
    value: "#f0f"
}, {
    color: "green",
    value: "#ff0"
}, {
    color: "black",
    value: "#000"
}];

data.forEach((o, i) => o.id = i + 1);

console.log(data);
Comment

PREVIOUS NEXT
Code Example
Typescript :: typescript hashmap 
Typescript :: latex two plots in 1 
Typescript :: Update Object Value in Ts/JS 
Typescript :: beautify typescript nodejs 
Typescript :: create custom objects for user in firebase 
Typescript :: typescript api request header 
Typescript :: how to check if key exists in Newtonsoft.Json object c# 
Typescript :: making barplots in r 
Typescript :: print all objects linked list python 
Typescript :: access single document with its id flutter 
Typescript :: router params angular 
Typescript :: typescript generic record 
Typescript :: react-excel-renderer typescript 
Typescript :: ts generics 
Typescript :: typescript import css 
Typescript :: cannot find file does not match the corresponding name on disk 
Typescript :: Jquery hide() all elements with certain class except one 
Typescript :: How to add new row to a particular index of a ag grid using angular 7 
Typescript :: serenity.is hide form field 
Typescript :: React-native suppress the warning "VirtualizedLists should never be nested" 
Typescript :: typoescript find multiple items in array and return found 
Typescript :: [(ngModel)] input error 
Typescript :: js pop object from id 
Typescript :: Index signature property 
Typescript :: how to search for elements that are on the webpage using html 
Typescript :: typescript pick 
Typescript :: elements without corner css 
Typescript :: react native type png 
Typescript :: object is possibly 
Typescript :: mongodb find documents where two fields are equal 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =