How do I delete a specific element from an array in JavaScript

0 votes
Can you help me with a problem that asks how to delete a specific element from an array in JavaScript?
Jan 9, 2025 in Java-Script by Ashutosh
• 33,370 points
• 1,044 views

1 answer to this question.

0 votes

You can use the splice() method.

Code:

let arr = [1, 2, 3, 4, 5];

// Remove the element at index 2

arr.splice(2, 1);

console.log(arr); // Output: [1, 2, 4, 5]

Explanation:

splice(index, count) modifies the array in place.

index: The position where deletion begins.

count: Number of elements to delete.

answered Jan 10, 2025 by Navya

Related Questions In Java-Script

0 votes
0 answers

How do I check if an array includes a value in JavaScript?

What is the quickest and most effective method to determine whether a JavaScript array has a value? The only method I am aware of is as follows: function contains(a, obj) { ...READ MORE

Sep 23, 2022 in Java-Script by Abhinaya
• 1,160 points
• 1,528 views
0 votes
1 answer
0 votes
1 answer

How do I check if an element is hidden in jQuery?

Hello @kartik,  You can use CSS: class .hide { ...READ MORE

answered Jun 8, 2020 in Java-Script by Niroj
• 82,800 points
• 2,224 views
0 votes
1 answer

How do I remove a property from a JavaScript object?

Objects in JavaScript can be thought of ...READ MORE

answered Jun 8, 2020 in Java-Script by Niroj
• 82,800 points
• 2,704 views
0 votes
1 answer

How can I configure lazy loading for Angular modules?

To configure lazy loading in Angular, you ...READ MORE

answered Dec 12, 2024 in Angular by Navya
• 1,327 views
0 votes
1 answer
0 votes
1 answer

How do I create a custom slider in React?

Create a custom slider in React by ...READ MORE

answered Feb 23, 2025 in Node-js by Kavya
• 1,129 views
0 votes
1 answer

How to generate optimized source with and without sourcemap for production use?

To generate optimized source code with or ...READ MORE

answered Dec 31, 2024 in PHP by Navya
• 2,573 views
0 votes
1 answer

How do I check if a variable is undefined in JavaScript?

In JavaScript, you can check if a ...READ MORE

answered Feb 7, 2025 in Java-Script by Navya
• 1,075 views
0 votes
1 answer

How can I replace every instance of a string in JavaScript?

In JavaScript, replacing all instances of a ...READ MORE

answered Jan 10, 2025 in Java-Script by Navya
• 1,202 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP