I want remove one item from my array. For example i want remove "Apple" from array. The code like below :
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2,1);
When i run this code, the output is ["Apple"]. The output should be ["Banana", "Orange", "Mango"]. Please help me to find what wrong with my code?
2 Answers 2
I am not sure, but yes, you must be taking extract from that splice, instead you need to take actual array as is.
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2,1);
console.log(fruits);
1 Comment
console.log(fruits.splice(2,1)) with expected the result of array. But now i know if it just return the value of splice. Once again thanks for you contribution :)The splice() method adds/removes items to/from an array, and returns the removed item(s). This link could help you: https://www.w3schools.com/jsref/jsref_splice.asp
Comments
Explore related questions
See similar questions with these tags.
["Banana", "Orange", "Mango"], check the value offruits. You might be looking at the return value ofsplice.["Apple"]because i try toconsole.log(fruits.splice(2,1))and like all you say it return value of splice not the value of array. After that i tryconsole('fruits')and it's return["Banana", "Orange", "Mango"]. Thanks for the solution @gurvinder372 @js_noob