0

I have an array of object as follow :

[ {label: "<p>Opacity | %<br/></p>", customRow: false, id: 0, items: Array(13)},
 {label: "Brand_hs_id", customRow: false, id: 0, items: Array(13)},
 {label: "<p>PPI |</p>", customRow: false, id: 0, items: Array(13)},
{label: "Brightness | %", customRow: false, id: 0, items: Array(13)
]

I want to findIndex of object where label value matches. for example if I pass the "Brightness | %" it should return 3.

I checked

const array1 = [5, 12, 8, 130, 44];

const isLargeNumber = (element) => element > 13;

console.log(array1.findIndex(isLargeNumber));
// expected output: 3

but not sure how to do it in array of objects .

2

2 Answers 2

0

Try something like as follows:

let val = [{id:"1002", address:"usa"},
           {id:"1004", address:"canada"},
           {id:"1006", address:"sweden"}];
    
let index = val.findIndex(x => x.address === "canada");

console.log(index); //Here index will be returned
Sign up to request clarification or add additional context in comments.

2 Comments

Always use var, let, or const to avoid creating leaked global. Use strict mode to see these errors.
const should be used here, as you'll not be reassigning the values.
-2

do it like this

const array1 = [{age:5}, {age:12},{age:8} , {age:130}, {age:44}];
const isLargeNumber = (element) => element.age > 13;

console.log(array1.findIndex(isLargeNumber));

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.