JSFiddle - React, Tailwind, and code Playground

by RaphaelDDL

HTML

click run if both below don't show up
    <hr>
        <hr>
            
<div id="output"></div>
<hr>
<div id="outputarray"></div>

JavaScript

var someArray = [{
    id: 'someID',
    name: 'someName',
    title: 'someTitle'
}, {
    id: 'anotherID',
    name: 'anotherName',
    title: 'anotherTitle'
}, {
    id: 'otherID',
    name: 'otherName',
    title: 'otherTitle'
}];

var posIndex = '';
$.each(someArray, function (i) {
    if (someArray[i].id === 'anotherID') {
        posIndex = i;
        return false;
    }
});

$("#output").text(posIndex);

/* ============================ */

var someOtherArray = [{
    id: 'anotherID',
    name: 'someName',
    title: 'someTitle'
}, {
    id: 'anotherID',
    name: 'anotherName',
    title: 'anotherTitle'
}, {
    id: 'otherID',
    name: 'otherName',
    title: 'otherTitle'
}];

var posIndexArray = [];
$.each(someOtherArray, function (i) {
    if (someOtherArray[i].id === 'anotherID') {
        posIndexArray.push(i);
    }
});

$("#outputarray").text(posIndexArray);