js实现抽取
使用 String.prototype.slice() 方法
通过指定起始和结束索引来截取字符串的一部分。
const str = 'Hello, world!';
const extracted = str.slice(0, 5); // 提取前5个字符
console.log(extracted); // 输出: "Hello"
使用 String.prototype.substring() 方法
类似于 slice,但不支持负数索引。
const str = 'Hello, world!';
const extracted = str.substring(7, 12); // 提取第7到12个字符
console.log(extracted); // 输出: "world"
使用 String.prototype.substr() 方法(已废弃)
指定起始索引和长度来截取字符串。

const str = 'Hello, world!';
const extracted = str.substr(7, 5); // 从第7个字符开始提取5个字符
console.log(extracted); // 输出: "world"
使用正则表达式提取匹配内容
通过正则表达式匹配并提取符合规则的子串。
const str = 'Phone: 123-456-7890';
const extracted = str.match(/\d{3}-\d{3}-\d{4}/)[0];
console.log(extracted); // 输出: "123-456-7890"
使用数组的 slice 方法提取部分元素
适用于从数组中提取部分元素。

const arr = [1, 2, 3, 4, 5];
const extracted = arr.slice(1, 4); // 提取索引1到3的元素
console.log(extracted); // 输出: [2, 3, 4]
使用解构赋值提取对象属性
适用于从对象中提取特定属性。
const obj = { name: 'Alice', age: 25, city: 'New York' };
const { name, city } = obj;
console.log(name, city); // 输出: "Alice New York"
使用 Array.prototype.filter() 提取符合条件的元素
适用于从数组中筛选符合条件的元素。
const arr = [10, 20, 30, 40, 50];
const extracted = arr.filter(num => num > 25);
console.log(extracted); // 输出: [30, 40, 50]
使用 Array.prototype.map() 提取特定字段
适用于从对象数组中提取特定字段。
const users = [{ id: 1, name: 'Bob' }, { id: 2, name: 'Alice' }];
const extracted = users.map(user => user.name);
console.log(extracted); // 输出: ["Bob", "Alice"]






