There is an array
of JSON
s :
var a = [ {id:1, latlong:[...]} , {id:2, latlong:[...]} , ... ];
How to get the JSON element which key id
equals 2 for example ?
There is an array
of JSON
s :
var a = [ {id:1, latlong:[...]} , {id:2, latlong:[...]} , ... ];
How to get the JSON element which key id
equals 2 for example ?
You can use array filter
which will return an array of objects. Then use index (example [0]
in this code) to retrieve the first object
var a = [{
id: 1,
latlong: ''
}, {
id: 2,
latlong: ''
}];
let newVal = a.filter(e => e.id === 2)[0];
console.log(newVal)