js原生api查漏补缺

Array数组
array.entries()

没有参数,得到的是一个遍历器。

const array1 = ['a', 'b', 'c', 'd', 'e'];
const bbb=Array.from(array1.entries()).map(([key,val]) => {
    console.log(key,val);
});;
console.log(Object.prototype.toString.call(array1.entries()));
打印出来的是 [object Array Iterator]

得到的是数组的遍历器。可以用for循环去遍历,不能使用数组的方法。

array.every(curr,index,arr)
const array1 = [1,2,4,5,8];
// curr 当前值
// index 当前下标
// 遍历的数组
// 返回值,boolean
const bbb=array1.every((curr,index,arr)=>{
    console.log(curr,index,arr);
    return curr >0;
})
console.log(bbb);
array.fill()
const array1 = [1,2,4,5,8];
const bbb=array1.fill(0,2,4);
// 三个参数,第一个是填充的值,第二个开始。第三个结束,结束位置不替换
console.log(bbb);
array.flat()

将数组里面还有数组的情况拉平

var arr1 = [1, 2, [3, 4]];
arr1.flat(1); 
// 参数,深度,往下深度为几拉平,默认为1
// [1, 2, 3, 4]
Array.form
console.log(Array.from('foo'));
// expected output: Array ["f", "o", "o"]
	// 复制其他一切类数组的东西。做转换,形成数组
console.log(Array.from([1, 2, 3], x => x + x));
// 可以对源的每个元素进行处理在返回。
// expected output: Array [2, 4, 6]
Array.of
Array.of(7);       // [7] 
Array.of(1, 2, 3); // [1, 2, 3]
可以将参数转换为数组。
array.reduce
const array1 = [1, 2, 3, 4];
const reducer = (accumulator, currentValue) => accumulator + currentValue;
// accumulator是前面的计算结果,currentValue是当前值。
// 第一个参数是回调,第二个是初始计算的值。
// 1 + 2 + 3 + 4
console.log(array1.reduce(reducer,5));
// expected output: 15
array.slice
const animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];
// 截取字符串,从start开始截取到end结束。包含开始。不包含结束下标。不影响原数组

console.log(animals.slice(2,3));
console.log(animals)
array.some
const array = [1, 2, 3, 4, 5];

// 只要有一个满足条件就返回true
const even = (element) => element % 2 === 0;

console.log(array.some(even));
array.splice
// 删除替换,影响原数组,
const months = ['Jan', 'March', 'April', 'June'];
// 从下标为1,删除0个元素。并且在下标为1处插入一个元素。包含下标处。
months.splice(1, 0, 'Feb');
// inserts at index 1
console.log(months);
array.values
const array1 = ['a', 'b', 'c'];
// 得到的是一个数组 遍历器。不是数组。不能使用数组的方法。
const iterator = array1.values();
字符串String
str.anchor(name)

用name字符串创建一个html 的a标签。a标签的name属性是传入的参数,内容是当前字符串

str.charAt(index)

默认为o,返回指定下标的字符。

str.charCodeAt()

返回当前下标字符的编码,

str.endsWith
const str1 = 'Cats are the best!';
// 参数1,子串。父串长度。用于判断父串是否以子串结尾。可指定父串用于判断的长度
console.log(str1.endsWith('best', 17));
str.padEnd(length,str)
'abc'.padEnd(10);          // "abc       "
'abc'.padEnd(10, "foo");   // "abcfoofoof"
'abc'.padEnd(6, "123456"); // "abc123"
'abc'.padEnd(1);           // "abc"
// 填充字符串,
str.substring(start,end)

返回开始到结尾的一些子串。包含start,不包含end

Object
Objecgt.defineProperties
const object1 = {};

Object.defineProperties(object1, {
  property1: {
    value: 42,
    writable: true
      //属性有
      //1.configurable 可配置性
     // 2.enumerabble 可枚举型
     // 3.value 值
     // 4.writable 可写性
     // 5.get和set 	访问和设置值都会过这两个
     //  configurable、enumerable 和 writable 的默认值都是 false。
	//  value、get 和 set 字段的默认值为 undefined。
  },
  property2: {}
});

console.log(object1.property1);
// expected output: 42
Object.freeze()

冻结一个属性,不能向这个对象添加新的属性,不能删除已有属性,不能修改该对象已有属性的可枚举性、可配置性、可写性

Object.fromEntries()
const entries = new Map([
  ['foo', 'bar'],
  ['baz', 42]
]);

const obj = Object.fromEntries(entries);

console.log(obj);
// expected output: Object { foo: "bar", baz: 42 }
Object.is(v1,v2)

判断两个值是否是相同的值

Object.is('foo', 'foo');     // true
Object.is(window, window);   // true

Object.is('foo', 'bar');     // false
Object.is([], []);           // false
Object.isFrozen()

判断一个对象是否被冻结

object.hasOwnProperty(attr)

判断object对象里面是有有这个键

Function
call和apply

使用一个指定的 this 值和单独给出的一个或多个参数来调用一个函数,

和apply的区别是,call传递的是参数列表。而apply传递的是参数数组。数组里面的值都是参数。

bind

bind不是立即执行的,是在这个绑定的函数调用的时候传入的。this参数没有传或者是null和undefined的话默认为函数内部的this,