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 in Java-Script by Ashutosh
• 14,020 points
41 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 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
799 views
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,840 points
1,022 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,840 points
1,553 views
0 votes
1 answer

How do I select an element with its name attribute in jQuery?

Hello @kartik, You can use: jQuery('[name="' + nameAttributeValue + ...READ MORE

answered Jun 11, 2020 in Java-Script by Niroj
• 82,840 points
1,103 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
56 views
0 votes
0 answers

How do I create a custom slider in React?

Can you tell me How do I ...READ MORE

Dec 19, 2024 in Node-js by Ashutosh
• 14,020 points
56 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
474 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 in Java-Script by Navya
41 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