When using elementui, you often encounter a multi-level tree structure, but the backend often gives inconsistent fields to each level of the frontend. If you write a traversal loop to change it to be consistent, it is troublesome. It is better to directly transfer the array sent by the background. It is a string, and then replace the inconsistent fields in the string with consistent ones, and the method of how to replace the specified characters that need to be replaced in the string is delegated.
The case is as follows
1. Replace all characters that are a in the string with e
let str = 'abcabcabc';
str = str.replace(/a/g, 'e');
console.log(str);
// 打印结果: ebcebcebc
2. Replace the first character of a in the string with e
let str = 'abcabcabc';
str = str.replace(/a/, 'e');
console.log(str);
// 打印结果: ebcabcabc