我需要删除所有以对象中的元音开头的键,但我不知道该怎么做。这是我到目前为止所拥有的。在此示例中,仅应保留“芯片”密钥,而应删除所有其他密钥。你们能帮我解决这个问题吗?
'use strict'
function removeVowelKeys(object) {
for (let key in object) {
if (key[0] === 'a' || key[0] === 'A' || key[0] === 'u' || key[0] === 'U' ||
key[0] === 'i' || key[0] === 'I' || key[0] === 'o' || key[0] === 'O' ||
key[0] === 'e' || key[0] === 'E' || key[0] === 'y' || key[0] === 'Y' ) {
delete object.key
}
}
}
console.log(removeVowelKeys({
alarm: 'This is SPARTA!!!',
chip: 100,
isValid: false,
Advice: 'Learn it hard',
onClick: 'make it great again',
}));
牧羊人nacy
拉莫斯之舞
相关分类