var parents = ["Jani", "Tove"];
var brothers = ["Stale", "Kai Jim", "Borge"];
var children = ["Cecilie", "Lone"];
var family = parents.concat(brothers, children);
console.log("p ",parents)
console.log("brothers ",brothers)
console.log("children ",children)
console.log("family ",family)
console.log("pop = ",family.pop())
console.log("f = ",family)
let num = family.push('yyyyy','zzz','aaa');
console.log('ff = ',family)
console.log('num = ',num)
let ft = family.reverse();
ft.pop();
console.log('ft = ',ft);
console.log("fan = ",family)
family.shift()
console.log("shift = ",family)
let sl = family.slice(2,4);
console.log("sl = ",sl);
console.log('fa = ',family);
let sp = family.splice(2,3,'j1','j2')
console.log('splice = ',family);
console.log("sp = ",sp);
let uncount = family.unshift('a1','a2');
console.log('uncount = ',uncount)
console.log('f = ',family);
结果:
p [ 'Jani', 'Tove' ]
brothers [ 'Stale', 'Kai Jim', 'Borge' ]
children [ 'Cecilie', 'Lone' ]
family [
'Jani', 'Tove',
'Stale', 'Kai Jim',
'Borge', 'Cecilie',
'Lone'
]
pop = Lone
f = [ 'Jani', 'Tove', 'Stale', 'Kai Jim', 'Borge', 'Cecilie' ]
ff = [
'Jani', 'Tove',
'Stale', 'Kai Jim',
'Borge', 'Cecilie',
'yyyyy', 'zzz',
'aaa'
]
num = 9
ft = [
'aaa', 'zzz',
'yyyyy', 'Cecilie',
'Borge', 'Kai Jim',
'Stale', 'Tove'
]
fan = [
'aaa', 'zzz',
'yyyyy', 'Cecilie',
'Borge', 'Kai Jim',
'Stale', 'Tove'
]
shift = [
'zzz', 'yyyyy',
'Cecilie', 'Borge',
'Kai Jim', 'Stale',
'Tove'
]
sl = [ 'Cecilie', 'Borge' ]
fa = [
'zzz', 'yyyyy',
sp = [ 'Cecilie', 'Borge', 'Kai Jim' ]
uncount = 8
f = [
'a1', 'a2',
'zzz', 'yyyyy',
'j1', 'j2',
'Stale', 'Tove'
]