标签:tostring log define des string each [] script ons
let a = [0, "a", "B", true, undefined, "", undefined, false, 0, null, 100, null, "a", "b", "", true];
console.log(a.toString());
a = fn(a);
console.log(a.toString());
function fn(a) {
if (a instanceof Array) {
let b = [];
a.forEach(item => {
if (!b.includes(item)) {
b.push(item);
}
});
return b;
} else {
return a;
}
}
let a = [0, "a", "B", true, undefined, "", undefined, false, 0, null, 100, null, "a", "b", "", true];
console.log(a.toString());
a = fn(a);
console.log(a.toString());
function fn(a) {
if (a instanceof Array) {
let b = [...new Set(a)];
return b;
} else {
return a;
}
}
标签:tostring log define des string each [] script ons
原文地址:https://www.cnblogs.com/zhaoziwei/p/10710395.html