var copy = JSON.parse(JSON.stringify(array));
Copying an array of objects into another array in javascript (Deep Copy)
Simple array like [1, 2, 3]
var copy = array.slice()
str1.localeCompare(str2, 'zh-CN')
function unique(arr) {
return arr.filter(function(item, index, arr) {
//当前元素,在原始数组中的第一个索引==当前索引值,否则返回当前元素
return arr.indexOf(item, 0) === index;
});
}
var arr = [1,1,'true','true',true,true,15,15,false,false, undefined,undefined, null,null, NaN, NaN,'NaN', 0, 0, 'a', 'a',{},{}];
console.log(unique(arr))
//[1, "true", true, 15, false, undefined, null, "NaN", 0, "a", {…}, {…}]// reference: https://attacomsian.com/blog/javascript-generate-random-string#:~:text=There%20are%20many%20ways%20available%20to%20generate%20a,a%20string%20and%20then%20remove%20the%20trailing%20zeros%3A
const randomString = (length = 8) => {
// Declare all characters
let chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
// Pick characers randomly
let str = '';
for (let i = 0; i < length; i++) {
str += chars.charAt(Math.floor(Math.random() * chars.length));
}
return str;
};