Skip to content

Tag: push

jQuery sort() is not working in function()

I am trying to sort the array after adding new entry into the array using push(). However there are 2 errors. First the sort() is not allowed. Second is when I remove the sort() the new entry always showed with a number of 5 attached Answer When adding new object into an array, you only need to use arr.push(obj), and

Javascript – push String to Array returns Integer

I add some strings in an array. Why I receive number 2 in the second log when name is a String too? I tried also let arr2 = arr1.slice().push(name); without success. Answer arr.push() modifies the arr itself and returns the length of the resulting array, to do what you want to do, you can do one of the two following