var prettyGirl = ['I', 'can', 'swear'];
prettyGirl.push('I', 'can', 'joke');
prettyGirl.push.apply(prettyGirl, ['I', 'say', 'whats', 'on', 'my', 'mind']);
prettyGirl.splice(-3).forEach((word) => {
alert(word);
});
Above the -3 behaves like a 9 and we get three alerts containing:
- on
- my
- mind
Here the -7 acts like a 5.
var prettyGirl = ['I', 'can', 'swear'];
prettyGirl.push('I', 'can', 'joke');
prettyGirl.push.apply(prettyGirl, ['I', 'say', 'whats', 'on', 'my', 'mind']);
prettyGirl.splice(-7, 3).forEach((word) => {
alert(word);
});
Giving...
- joke
- I
- say
No comments:
Post a Comment