Use Filter function :
From Eloquent Javascript Book: “Note how the filter function, rather than deleting elements from the existing array, builds up a new array with only the elements that pass the test. This function is pure. It does not modify the array it is given.”
Example:
// Create the original array.
var arr = [5, "element", 10, "the", true];
// Create an array that contains the string
// values that are in the original array.
var result = arr.filter(
function (value) {
return (typeof value === 'string');
}
);
document.write(result);
// Output: element, the