Last active
October 24, 2015 16:40
-
-
Save rtivital/077811bb6d4db56c156a to your computer and use it in GitHub Desktop.
Удаление всех ложных свойств из массива
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Используйте метод массивов filter, | |
// чтобы удалить все ложные свойства из массива | |
var arr = ['', 1, 'str 1', 0, false, 'str 2', null]; | |
// Функция Boolean() возвращает только значения true и false | |
arr.filter(Boolean); // [1, 'str1', 'str 2'] | |
// Сокращенный вариант функции | |
arr.filter(function(item) { | |
return !!item; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment