,可以按照以下步骤进行:
下面是一个示例代码:
function findObjectKeysInString(inputString, object) {
var keys = Object.keys(object);
var foundKeys = [];
var index = 0;
var length = keys.length;
while (index < length) {
var key = keys[index];
if (inputString.indexOf(key) !== -1) {
foundKeys.push(key);
}
index++;
}
return foundKeys;
}
// 示例用法
var inputString = "This is a test string";
var object = {
key1: "value1",
key2: "value2",
key3: "value3"
};
var result = findObjectKeysInString(inputString, object);
console.log(result);
这个代码将在输入字符串中查找对象的键,并返回一个包含找到的键的数组。你可以根据实际情况进行修改和调整。
领取专属 10元无门槛券
手把手带您无忧上云