ES6学习笔记之数组

2017-07-13  本文已影响14人  awesome_lewis
function addUp() {
  let total = 0;
  for(let num of arguments) {
    total += num;
  }
  return total;
}

addUp(1, 2, 3, 4);  // 10
function addUp() {
  const nums = Array.from(arguments);
  return nums.reduce((prev, next) => prev + next, 0)
}

addUp(1, 2, 3, 4);  // 10
<div class="people">
  <p>Jay</p>
  <p>Eason</p>
  <p>David</p>
</div>
const people  = Array.from(document.querySelectAll('.people p'));
const names = people.map(person => person.textContent);
console.log(names);  // ['Jay', 'Eason', 'David']
上一篇 下一篇

猜你喜欢

热点阅读