codecamp

Lodash _.pullAt

_.pullAt(array, [indexes])

根据索引 indexes,移除array中对应的元素,并返回被移除元素的数组。Note: 和_.at不同, 这个方法会改变数组 array。

引入版本

3.0.0

参数

  1. array (Array): 要修改的数组。
  2. [indexes] (...(number|number[])): 要移除元素的索引。

返回值

(Array): 返回移除元素组成的新数组。

例子

var array = [5, 10, 15, 20];var evens = _.pullAt(array, 1, 3); 
console.log(array);
// => [5, 15] 
console.log(evens);
// => [10, 20]


Lodash _.pullAllWith
Lodash _.remove
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

Lodash 简介

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }