面试题答案
一键面试function extractStrings(arr: (string | number | boolean | null)[]): string {
let result = '';
for (let item of arr) {
if (typeof item ==='string') {
result += item;
}
}
return result;
}
示例调用:
const mixedArray: (string | number | boolean | null)[] = ['hello', 123, true, null, 'world'];
const extractedString = extractStrings(mixedArray);
console.log(extractedString);