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
The indexOf() method of Array instances returns the first index at which a given element can be found in the array, or -1 if it is not present.
🌐
W3Schools
w3schools.com › jsref › jsref_indexof_array.asp
JavaScript Array indexOf() Method
The indexOf() method returns the first index (position) of a specified value.
Discussions

javascript - Using the indexOf method on an array of objects - Stack Overflow
I like Pablo's answer, but Array#indexOf and Array#map don't work on all browsers. Underscore will use native code if it's available, but has fallbacks as well. More on stackoverflow.com
🌐 stackoverflow.com
How to get indexOf() from an id that's inside an object that's inside an array? I have provided an example.
Array.prototype.findIndex takes a function as its argument. That's right, functions themselves can be passed into functions! First, we can define a function that returns true if the uniqueId is 2 and false otherwise. function uniqueIdIsTwo(user) { return user.uniqueId === 2 } Then we can pass that function as the parameter of findIndex const index = myArray.findIndex(uniqueIdIsTwo) Notice how we're passing the function itself, we're not calling it! findIndex takes care of calling our function. In fact, findIndex calls our function for every element of the array and comes back with the index when our function returns true (or returns the magical -1 if our function never returns true). It's annoying to define a separate function each time, so we can also use an anonymous function instead. Anonymous means it doesn't have a name. Naming things is hard, so this is a useful thing to avoid naming it! const index = myArray.findIndex(function(user) { return user.uniqueId === 2}) Finally, we can also use arrow functions, which are a little more concise. There are differences between arrow functions and "regular" functions that are important to learn (some other time) but they are not different for this particular case. const index = myArray.findIndex(user => user.uniqueId === 2) More on reddit.com
🌐 r/learnjavascript
30
31
November 3, 2021
Are there any inbuilt functions in Javascript to find the insertion index of a number in an array?
It's not a terribly common scenario. If you want data to remain sorted and you cared about performance, you would normally leverage a sorted data structure (there are various trees structures that support this), rather than a dynamic array. Inserting in the middle of a dynamic array is a very inefficient operation in the worst case O(n) in the length of the array, and so is usually only a good idea on relatively small arrays. And if your array is small, might as well just append at the end and sort it, or just use a simple linear scan on the array using index of. Those few cycles won't matter conpared to network overhead anyway. Fortunately almost all arrays you will work with day to day are small. This is the kind of task that feels common in leetcode, but is rareish in production use cases. More on reddit.com
🌐 r/learnprogramming
9
0
September 15, 2023
How to do the indexOf() method for an array of arrays
Think about what your if statement is doing. If the array element does not match then immediately return false. Do you see why that may be a problem? As a side note I would stick to only returning a single type from a function. Returning an integer or a boolean can trip you up later. More on reddit.com
🌐 r/learnprogramming
8
0
January 4, 2025
🌐
Mimo
mimo.org › glossary › javascript › array-indexof-method
JavaScript Array indexOf() method: Syntax, Usage, and Examples
The indexOf() method lets you search an array for a specific value and returns its first index. If the value isn’t found, it returns -1. The JavaScript array indexOf method is a quick and reliable way to determine the position of an element in an array, especially when working with primitive ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-array-indexof-method
JavaScript Array indexOf() Method - GeeksforGeeks
September 27, 2024 - The method returns the index of the first occurrence of the specified element. If the element is not found, it returns -1. This code demonstrates the use of the indexOf() method to find the index of the element "gfg" in the array name.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Array methods
const arr = [NaN]; alert( arr.indexOf(NaN) ); // -1 (wrong, should be 0) alert( arr.includes(NaN) );// true (correct) That’s because includes was added to JavaScript much later and uses the more up-to-date comparison algorithm internally. Imagine we have an array of objects.
Find elsewhere
🌐
Programiz
programiz.com › javascript › library › array › indexof
JavaScript Array indexOf()
var index4 = priceList.indexOf(69.5); console.log(index4); // -1 ... If fromIndex >= array.length, array is not searched and -1 is returned.
🌐
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.
🌐
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

🌐
W3Schools
w3schools.com › js › js_array_search.asp
JavaScript Array Search
JavaScript Array Reference · The indexOf() method searches an array for an element value and returns its position. Note: The first item has position 0, the second item has position 1, and so on.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › findIndex
Array.prototype.findIndex() - JavaScript | MDN
Array.prototype.indexOf() Array.prototype.lastIndexOf() TypedArray.prototype.findIndex() Was this page helpful to you? Yes · No Learn how to contribute · This page was last modified on Jul 20, 2025 by MDN contributors.
🌐
TutorialsPoint
tutorialspoint.com › home › javascript › javascript array indexof method
JavaScript Array indexOf Method Explained
September 1, 2008 - The JavaScript Array indexOf() method is used to return the first occurrence index of a specified element within an array (if it is present at least once).
🌐
Tabnine
tabnine.com › home › how to use the indexof method in javascript
How to Use the indexOf method in JavaScript - Tabnine
July 25, 2024 - For Arrays, the comparison of the searchValue to each array element is performed using the strict equality operator (===). Thus, you must provide the exact value of the item you are searching for when searching Arrays. console.log(fruits.indexOf('appl')); // Expected output: -1
🌐
DigitalOcean
digitalocean.com › community › tutorials › js-indexof
Exploring the indexOf Method for Strings and Arrays in JavaScript | DigitalOcean
December 17, 2019 - In its simplest version, the indexOf method takes one argument which is the element we are trying to find. Then it returns the index of the first element it finds in the array which satisfies el === target. This means that even if there are two matches in your array, indexOf will only return ...
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › Array › indexOf
JavaScript Array indexOf() - Locate Element Index | Vultr Docs
November 28, 2024 - Define an array with several elements. Use the indexOf() method to find the index of a specific element.
🌐
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);
🌐
Medium
medium.com › @soni.dumitru › when-to-use-array-prototype-indexof-7575ff1c50fb
indexOf(), find() and includes() — JavaScript | by sonia dumitru | Medium
October 27, 2019 - The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Indexed_collections
Indexed collections - JavaScript | MDN
For example, consider an array called emp, which contains employees' names indexed by their numerical employee number. So emp[0] would be employee number zero, emp[1] employee number one, and so on. JavaScript does not have an explicit array data type. However, you can use the predefined Array object and its methods to work with arrays in your applications.
🌐
YouTube
youtube.com › watch
JavaScript for Beginners #33 indexOf() Method for Arrays - YouTube
Here, we will learn about the indexOf() method for arrays in JavaScript. The indexOf() method will search an array and return the first index at which a give...
Published   February 5, 2021