How can I get the index from a JSON object with value ? Last Updated : 22 Nov, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we are going to learn how you get an index from a JSON object with value. we have given a value we need to search for that value with its key in the given JSON object and print the result in the console. These are the following approaches: Table of Content Using the Array.find() methodUsing findIndex() methodApproach 1: Using the Array.find() methodIn this approach, we are going to use the Array.find() method which is used to find the value in an array. Example: In this example, we will use Array.find() to find the Index of the object. JavaScript let data = [{ "name": "HTML", "description": "HyperText Markup Language" }, { "name": "CSS", "description": "Cascade Style Sheet" }, { "name": "JS", "description": "JavaScript" }] let index = -1; let val = "JS" let filteredObj = data.find(function (item, i) { if (item.name === val) { index = i; return i; } }); if (index == -1) { console.log("Data not found!") } else { console.log(filteredObj.name, "is at index", index); } Output: JS is at index 2Approach 2: Using findIndex() methodIn this approach, we are using the findIndex() method. This method is used to find the given value in an array and returns it's index if the value is present in that array. Example: In this example, we will use findIndex() method to find the Index of the object with "name":"CSS" JavaScript let data = [{ "name": "HTML", "description": "HyperText Markup Language" }, { "name": "CSS", "description": "Cascade Style Sheet" }, { "name": "JS", "description": "JavaScript" }] let index = -1; index = data.findIndex(obj => obj.name == "CSS"); if (index == -1) { console.log("Data not found!") } else { console.log("Index is", index); } Output: Index is 1 NOTE: The array.findIndex() method works similarly to array.find(), but it returns the index of the first element that matches the condition, rather than the element itself. Comment More infoAdvertise with us Next Article How to get a key in a JavaScript object by its value ? 21mcsrltd Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League javascript-object Geeks Premier League 2023 +1 More Similar Reads How to delete an index from JSON Object ? Deleting an index from a JSON object involves removing a specific key-value pair from the object structure. This is often done to clean up data, remove sensitive information, or modify the object for specific use cases, ensuring only relevant information remains accessible.Now, to delete any index f 2 min read How to get a key in a JavaScript object by its value ? To get a key in a JavaScript object by its value means finding the key associated with a specific value in an object. Given an object with key-value pairs, you want to identify which key corresponds to a particular value, often for searching or data retrieval.How to get a key in a JavaScript object 4 min read How to get the Index of an Array based on a Property Value in TypeScript ? Getting the index of an array based on a property value involves finding the position of an object within the array where a specific property matches a given value. The below approaches can be used to accomplish the task. Table of Content Using Array.findIndex()Using reduce() methodUsing for loopUsi 4 min read How to Get all Property Values of a JavaScript Object without knowing the Keys? To get all property values from a JavaScript object without knowing the keys involves accessing the object's properties and extracting their values.Below are the approaches to get all property values of a JavaScript Object:Table of ContentUsing Object.values() MethodUsing Object.keys() methodApproac 2 min read How to change JSON String into an Object in JavaScript ? In this article we are going to learn how to change JSON String into an object in javascript, JSON stands for JavaScript object notation. It is the plain format used frequently as a communication medium on the internet. It appears close to OOP language like JavaScript but cannot be accessed like Jav 3 min read How to get the first key name of a JavaScript object ? In JavaScript, accessing the first key name of an object involves identifying the initial property defined within that object. This concept is useful when you need to interact with or manipulate object properties in a specific order, particularly when the sequence of properties is relevant.Here we h 2 min read Like