// Get the index of an obj by using its id as param
function teste(id) {
// use findeIndex() to get the id of an array of objects that would match the param
const index = data.findIndex((item) => item.id === id);
// then, you can use this as base for statements
id === data[index].id ? doSomething() : doOtherThing();
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter