How do we search a specific element in an array?



How do we search a specific element in an array?..

Answer / Abhijit Mehrotra

To find a specific element in a JavaScript array, you can use the indexOf() method. The indexOf() method returns the index of the first occurrence of the specified element if it is present, otherwise -1.nnExample:n```javascriptnlet arr = [1, 2, 3];nconsole.log(arr.indexOf(2)); // 1```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Data Structures Interview Questions

Is array of data structure?

1 Answers  


Define separate chaining?

1 Answers  


Can we null keys in treemap?

1 Answers  


How can avl tree be useful in all the operations as compared to binary search tree?

1 Answers  


Define binary tree insertion.

1 Answers   Tech Mahindra,


List the data structures which are used in rdbms, network data modal, and hierarchical data model.

1 Answers  


Where will be the free node available while inserting a new node in a linked list?

1 Answers  


how to insert a new node in linked list where free node will be available?

1 Answers  


What is a Breadth First Search? Give a few of its applications.

1 Answers   Ciena,


What is sequential sorting?

1 Answers  


How does the size of arraylist increases dynamically?

1 Answers  


what is the difference between dynamic as well as non - dynamic data structures.

1 Answers   Aricent,


Categories