![]() ![]() In the end, we show it in the console.log We are simply passing the item of the array for which we want to get the index number. The JS indexOf() method is searching the array for a particular item and then returns its position. This method is responsible to do our job. From the items, we find the index number of “Monkey” to get the position.Īs you can see, we have used the indexOf() JavaScript method. As you can see, the array contains some animal names as items. First of all, we take an array and assigned it inside the variable animals. In the above example, we are able to do our task successfully. Var arrIndex = animals.indexOf("Monkey") See the complete code example below to get and show the result in the console log: var animals = It can be done just by using simple javaScript code and an in-built method. After that, we will perform our simple operation to get the position of the specific element in from the array. Here in this task, we are going to take a JavaScript array and then find the index of a particular element to get the position of that item.īefore we go through, first we need to take an array. ![]() Each javaScript array item has an index number that tells us the position of that item in that array. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |