Array.of and Array.from learning

The Array.from method is used to convert two types of objects into real arrays, array-
like objects,
traversable objects

In practical applications, common array-like objects are the NodeList collection returned by DOM operations and the arguments object inside the function. Array.from can turn them into real arrays.

// NodeList对象
let ps = document.querySelectorAll('p');
Array.from(ps).filter(p => {
    
    
  return p.textContent.length > 100;
});

// arguments对象
function foo() {
    
    
  var args = Array.from(arguments);
  // ...
}

Guess you like

Origin blog.csdn.net/Beth__hui/article/details/109382347