Explore Courses Blog Tutorials Interview Questions
0 votes
in Java by (13.1k points)
I have a created an array and now I want to delete a specific element in an array using JavaScript. Can anyone help me how I can able to do this?

1 Answer

0 votes
by (26.7k points)

Basically, in able to remove the specific element from an array, first you need to find the index of an element with the help of indexOf and can able to remove it using splice function. Below is the code for your reference:

const intel = [1, 5, 10];


const index = intel.indexOf(5);

if (index > -1) {

  intel.splice(index, 1);


// intel = [1, 10]


I hope this will help.

Want to know more about Java? Prefer this tutorial on Learn Java.

Want to become a Java expert? Join Java Certification now!!

Related questions

Browse Categories