js 改变数组中每条对象的属性名 一、改变一个属性名:数据量少可以,多了比较耗性能 1234567891011121314151617181920212223242526272829<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>js< javascript #js #javascript
js 数组中的字符转为数字 本来是这样的: [“3”, “17”, “56”, “21”, “8”, “33”, “177”] 转化后: [3, 17, 56, 21, 8, 33, 177] 方法:(选其一中) 数组.map(Number) JSON.parse(‘[‘ + String(数组) + ‘]’) eval(‘[‘ + String(数组) + ‘]’) 数组.map((i)=> javascript #js #javascript
js 数组倒序排列 1.使用reverse()函数:123var array=['我','喜','欢','你']; array.reverse(); // 输出: ["你", "欢", "喜", "我"] 2.循环遍历一一使其倒序:12345678va javascript #js #javascript
js 数组后面追加一个数组,连接数组 方法: 数组.concat(追加的数组); 示例: 1234var a = [1,2,3];var b = [4,5,6];conslle.log(a.concat(b)); // 输出结果:[1,2,3,4,5,6] javascript #js #javascript
js 数组的常用操作函数 12var array = ["jeiw","sfwe","fasfwe","ftqq","hjweq","jfoiwe"]; var newArrray = ["qqq","www","eee","rrr javascript #js #javascript
js 数组转字符串,字符串转数组 数组转字符串12345var arr=["呀覅发","附件我发我","就让我委","那就按嗯"]; console.log(arr.join()); //默认按,分割console.log(arr.join("-")); //按-分割console.log(arr.join("/&q javascript #js #javascript
js 查询关键字后高亮显示 效果 源码1234567891011121314151617181920212223242526272829303132333435363738<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>测试</tit javascript #js #javascript
js 正则匹配,从字符串中提取数字 效果: 正则: /[^\d.]/g 代码:123let string = "谷(2588.7元/kwh)";let num = string.replace(/[^\d.]/g, "");console.log(num); javascript #js #javascript
js 浏览器窗口活跃监听 12345678910111213141516171819202122232425262728<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title></head> javascript #js #javascript