How do I find an object key written in any format?

时间:2018-06-04 17:05:49

标签: javascript javascript-objects

I'm trying to find a string in any way it is written in an object received.

example

"OUTPUT", "OUT PUT", "out put", "ouT Put"

test.hasOwnProperty("OUTPUT") works for only this case. I do not want to repeat the same for each case. Is there a better way to get this done?

1 个答案:

答案 0 :(得分:0)

var object = {"OUTPUT":"value"};

var prop1 = "OUTPUT",
prop2 = "OUT PUT",
prop3 = "out put",
prop4="ouT Put";

console.log(object.hasOwnProperty(encodeURI(prop2).replace(/%20/g,'').toUpperCase()));

console.log(object.hasOwnProperty(encodeURI(prop2).replace(/%20/g,'').toUpperCase()));

console.log(object.hasOwnProperty(encodeURI(prop2).replace(/%20/g,'').toUpperCase()));

console.log(object.hasOwnProperty(encodeURI(prop2).replace(/%20/g,'').toUpperCase()));

相关问题