According to the $.grep() documentation, I would have thought that the code below would print 2 . But instead, it prints 0,1,2 . See this script . Am I going to loco?
$.grep()
2
0,1,2
var arr = [0, 1, 2]; $.grep( arr, function(n,i) { return n > 1; }); $('body').html( arr.join() );
$.grep returns a new array - it does not modify your existing one.
$.grep
Do you want to
arr = $.grep( arr, function(n,i) { return n > 1; });
Check out $. grep docs for more information
You are missing the key part.
"Description: Finds array elements that satisfy the filter function. The original array does not change."
var newArray = $.grep( arr, function(n,i) { return n > 1; }); $('body').html( newArray.join() );
Source: https://habr.com/ru/post/1388041/More articles:App still running in background Xcode 4.2 iOS 5 - iphoneHow to install gujarati for textview in android application? - androidCan 'false' match some string in mysql? - mysqlPHP PEAR, how to check default directories? - phpPython: request url via POST and show result in browser - pythonA-star: heuristic for several purposes - algorithmRails 3.1 named_scope - ruby ββ| fooobar.comChanging buffer focus control (pop-to-buffer vs display-buffer) - emacsAre jQuery utility functions preferable to regular function definitions? - javascriptFlex Mobile Alarm - Local Notification - androidAll Articles