Middle
const items = [10, '10', 12, 15, 21, 12, 10, 16, 21, 15, 'apple', 'apple']; function createUniqueArray(values) { return values; }
sobes.tech AI
Answer from AI
To create an array with unique values from the original array, you can use the Set object, which stores only unique elements:
const items = [10, '10', 12, 15, 21, 12, 10, 16, 21, 15, 'apple', 'apple'];
function createUniqueArray(values) {
return Array.from(new Set(values));
}
console.log(createUniqueArray(items));
// Output: [10, '10', 12, 15, 21, 16, 'apple']
Note that numbers and strings with the same content are considered different elements (10 and '10').