I want to search an array of objects to find the index of specific id. let have a look:
here is the array of my objects:
var sentences = [0,
{ id: "1-1", layer: ["A1", "A2", "A3", "A4", "A5"], difficulty: 4, track: "end", start: 4, end: 6, accuracy: undefined , accent: undefined, meaning_weight: undefined, shadow_weight: undefined, write_weight: undefined },
{ id: "1-2", layer: ["A1", "A2", "A3", "A4", "A5"], difficulty: 4, track: "end", start: 4, end: 6, accuracy: undefined , accent: undefined, meaning_weight: undefined, shadow_weight: undefined, write_weight: undefined },
{ id: "1-3", layer: ["A1", "A2", "A3", "A4", "A5"], difficulty: 4, track: "end", start: 4, end: 6, accuracy: undefined , accent: undefined, meaning_weight: undefined, shadow_weight: undefined, write_weight: undefined },
{ id: "2-1", layer: ["A1", "A2", "A3", "A4", "A5"], difficulty: 4, track: "end", start: 4, end: 6, accuracy: undefined , accent: undefined, meaning_weight: undefined, shadow_weight: undefined, write_weight: undefined },
{ id: "2-2", layer: ["A1", "A2", "A3", "A4", "A5"], difficulty: 4, track: "end", start: 4, end: 6, accuracy: undefined , accent: undefined, meaning_weight: undefined, shadow_weight: undefined, write_weight: undefined },
{ id: "2-3", layer: ["A1", "A2", "A3", "A4", "A5"], difficulty: 4, track: "end", start: 4, end: 6, accuracy: undefined , accent: undefined, meaning_weight: undefined, shadow_weight: undefined, write_weight: undefined },
];
for example, I want to find the index of id: "2-1"
which is 4
. How can I do that?
I have tried some like this without any success...
pos = sentences.map(function(e) { return e.sentences.id; }).indexOf('2-1');
console.log(pos)