- 博客(6)
- 收藏
- 关注
原创 js中toString()和String()区别详解
我们知道String()与 .toString()都是可以转换为字符串类型,但是String()与 .toString()的还是有区别的1、.toString()可以将所有的的数据都转换为字符串,但是要排除null 和 undefined例如将false转为字符串类型var str = false.toString(); console.log(str, typeof str); 返回的结果为 false,string看看null 和 undefined能不能转换为字符串javascriptvar
2022-03-27 12:20:55
524
原创 在数组开头添加元素
在数组 arr 开头添加元素 item。不要直接修改数组 arr,结果返回新的数组leecode题利用concatfunction prepend(arr, item) { return [item].concat(arr);}使用push.applyfunction prepend(arr, item) { var newArr=[item]; [].push.apply(newArr, arr); return newArr;}利用slice+unsh
2022-03-13 16:33:53
2939
原创 JavaScript在数组尾部添加元素
**JavaScript在数组尾部添加元素**在数组 arr 末尾添加元素 item。结果返回新的数组。注意:不要直接修改数组 arr!!!/* 1.使用for循环和push方法 */function append(arr, item) {const res = []for(let i=0;i<arr.length;i++) {res.push(arr[i])}res.push(item)return res;}/* 2.使用concat合并 */function app
2022-03-07 15:18:01
4493
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅