[removed] Quickly lookup value in object (like we can with properties)

后端 未结 4 549
名媛妹妹
名媛妹妹 2021-01-05 14:07

I have an object that has pairs of replacement values used for simple encoding / decoding (not for security, just for a convenience; too complicated to explain it all here).

4条回答
  •  旧巷少年郎
    2021-01-05 14:46

    If you're looking for array keys check here.

    https://raw.github.com/kvz/phpjs/master/functions/array/array_keys.js

    function array_keys (input, search_value, argStrict) {
        var search = typeof search_value !== 'undefined', tmp_arr = [], strict = !!argStrict, include = true, key = '';
    
        if (input && typeof input === 'object' && input.change_key_case) {
            return input.keys(search_value, argStrict);
        }
    
        for (key in input) {
            if (input.hasOwnProperty(key)) {
                include = true;
                if (search) {
                    if (strict && input[key] !== search_value) include = false;
                    else if (input[key] != search_value) include = false;
                }
                if (include) tmp_arr[tmp_arr.length] = key;
            }
        }
    
        return tmp_arr;
    }
    

提交回复
热议问题