Click here to Skip to main content
15,896,526 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can i remove element from array by index?

What I have tried:

I have tried like this, but it's not working.

function removeArray(x, n){
	for(var i = 0; i < x.length; i++){
		x = x.remove(n);
	}
	return x;
}
console.log(removeArray([20,11,12,13,14], 1));
Posted
Updated 18-Jul-18 7:44am

1 solution

I don't think you need a loop in the code. because index should be unique. Try this

JavaScript
function removeArray(x, n){
  x.splice(n, 1);
  return x;
}
console.log(removeArray([20,11,12,13,14], 1));


Output: 20,12,13,14

JavaScript Array splice() Method[^]
 
Share this answer
 
Comments
Suren97 18-Jul-18 13:53pm    
Thank you very much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900