I think you can solve it in one line using the map function:

const pos = myArray.map(e => e.hello).indexOf('stevie');
Answer from Pablo Francisco Pérez Hidalgo on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › indexOf
Array.prototype.indexOf() - JavaScript | MDN
const beasts = ["ant", "bison", "camel", "duck", "bison"]; console.log(beasts.indexOf("bison")); // Expected output: 1 // Start from index 2 console.log(beasts.indexOf("bison", 2)); // Expected output: 4 console.log(beasts.indexOf("giraffe")); // Expected output: -1 ... Element to locate in the array. ... Zero-based index at which to start searching, converted to an integer. Negative index counts back from the end of the array — if -array.length <= fromIndex < 0, fromIndex + array.length is used.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › system.array.indexof
Array.IndexOf Method (System) | Microsoft Learn
Searches for the specified object and returns the index of its first occurrence in a one-dimensional array. public: static int IndexOf(Array ^ array, System::Object ^ value);
🌐
Go Make Things
gomakethings.com › how-to-get-the-index-of-an-object-in-an-array-with-vanilla-js
How to get the index of an object in an array with vanilla JS | Go Make Things
var wizards = [ { name: 'Saruman', color: 'white' }, { name: 'Gandalf', color: 'gray' }, { name: 'Radagast', color: 'brown' }, { name: 'Alatar', color: 'blue' }, { name: 'Pallando', color: 'blue' } ]; // returns -1 wizards.indexOf({ name: 'Radagast', color: 'brown' }); Fortunately, ES6 introduced a new method that does exactly what we want: Array.findIndex(). The Array.findIndex() method works a lot like some of the other new ES6 array methods.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › findIndex
Array.prototype.findIndex() - JavaScript | MDN
The findIndex() method of Array instances returns the index of the first element in an array that satisfies the provided testing function. If no elements satisfy the testing function, -1 is returned.
🌐
W3Schools
w3schools.com › jsref › jsref_indexof_array.asp
JavaScript Array indexOf() Method
The indexOf() method starts at a specified index and searches from left to right (from the given start postion to the end of the array).
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-indexof-method-in-an-object-array
JavaScript indexOf() method in an Object Array - GeeksforGeeks
March 14, 2024 - In this case, the modified banana object is added to the array, and then indexOf() method returns the index where this modified object is located. ... // Example Title: Finding Index of a Modified Object // Array of objects representing fruits ...
Find elsewhere
🌐
W3docs
w3docs.com › javascript
How to Get the Index of an Array that Contains Objects in JavaScript
Javascript find index of an array that contains object · let array = [{ prop1: 'value1', }, { prop2: 'value2', }, { prop3: 'value3', }]; Array.prototype.indexOfObject = function (property, value) { for (let i = 0, len = this.length; i < len; i++) { if (this[i][property] === value) return i; } return -1; } console.log(array.indexOfObject("prop2", "value2")); Run > Reset ·
🌐
Reddit
reddit.com › r/learnjavascript › how to get indexof() from an id that's inside an object that's inside an array? i have provided an example.
r/learnjavascript on Reddit: How to get indexOf() from an id that's inside an object that's inside an array? I have provided an example.
November 3, 2021 -

Hi everyone, I have been stuck on this for about 10 hours now....

Let me post the code, then explain exactly what I need to do.

Here's my array:
myArray[obj, obj, obj];

Here's my objects that are inside the array:
obj {name : "keith", uniqueId : 0}
obj {name : "keith", uniqueId : 1}
obj {name : "keith", uniqueId : 2}

Here's what I need to do:

I need to get the indexOf() these objects based on that uniqueId. The objects will be moved around the array and could be in any position.

myArray[obj, obj, obj];
obj {name : "keith", uniqueId : 0} //myArray index 2
obj {name : "keith", uniqueId : 1} //myArray index 0
obj {name : "keith", uniqueId : 2} //myArray index 1

So how do I do this? I'd like to do something like:
indexOf(object with the unique id of 2) // 1

🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript array methods › array.prototype.indexof()
JavaScript Array indexOf() Method
November 6, 2024 - The Array indexOf() method returns the index of the first matching element in an array or -1 if there is no matching element.
🌐
GitHub
github.com › dim912 › Object-Array-IndexOf
GitHub - dim912/Object-Array-IndexOf: indexOf implementation for javascript object array
var oai = require('array-indexof-object') var arr = [ {"a":"1","b":"2"}, {"a":"5","b":"2"}, {"a":"1","b":"2"}, {"b":"7"},{"a":"3","b":"7"}] oai.firstIndexOf(arr, { "a": "5", "b": "2" }) //Return => 1 oai.allIndexesOf(arr, { "a": "1" })//Return => [0,2] oai.lastIndexOf(arr, { "a": "1" }) //Return => 2 oai.nthIndexOf(arr, { "b": "7" }, 2) //Return => 4
Author   dim912
🌐
Mimo
mimo.org › glossary › javascript › array-indexof-method
JavaScript Array indexOf() method: Syntax, Usage, and Examples
The indexOf() method finds the first index of a specified element in an array. If the element is not found in the array, it returns -1. This is most commonly used to check if an element exists or to get its position. ... Become a full-stack developer. Learn HTML, CSS, JavaScript, and React ...
🌐
GeeksforGeeks
geeksforgeeks.org › indexof-method-in-an-object-array-in-javascript
indexOf method in an object array in JavaScript - GeeksforGeeks
November 24, 2021 - If this method finds an array element for which the function returns a true value, this method returns the index of that array element and stops, Otherwise, it returns -1. ... Arr: This parameter is optional.
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript find index of object in array
How to Find Index of Object in JavaScript Array | Delft Stack
February 2, 2024 - This article will explore the findIndex() method and the use of lodash to find the object’s index inside JavaScript Array.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Get index of object in array
September 3, 2018 - How can I get the index of an obj in an array of objects? const arr = [ {x: "a", y: 1}, {x: "b", y: 2} ] const i = arr.indexOf({x: "a", y: 1}) console.log(i) // output: -1 I would expect the output to be 0, but it’s t…
🌐
CoreUI
coreui.io › answers › how-to-find-the-index-of-an-element-in-an-array-in-javascript
How to find the index of an element in an array in JavaScript · CoreUI
September 19, 2025 - The indexOf() method searches the array from the beginning and returns the index of the first occurrence of the specified element, or -1 if the element is not found. In this example, fruits.indexOf('banana') returns 1 because ‘banana’ first ...
🌐
freeCodeCamp
freecodecamp.org › news › javascript-standard-objects-arrays
JavaScript Standard Objects: Arrays
January 26, 2020 - If the element is not in the array, indexOf returns -1. ... fromIndex (Optional): The index at which you want to start the search at. If the fromIndex is greater than or equal to the array’s length, the array is not searched and the method returns -1. If the fromIndex is a negative number, it considered an offset from the end of the array (the array is still searched forwards from there).