Skip to content

Instantly share code, notes, and snippets.

@shakhal
Last active January 27, 2023 22:52
Show Gist options
  • Select an option

  • Save shakhal/3cf5402fc61484d58c8d to your computer and use it in GitHub Desktop.

Select an option

Save shakhal/3cf5402fc61484d58c8d to your computer and use it in GitHub Desktop.

Revisions

  1. shakhal revised this gist Nov 26, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions find_values.js
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ function findValuesHelper(obj, key, list) {
    if (!obj) return list;
    if (obj instanceof Array) {
    for (var i in obj) {
    list = list.concat(getNames(obj[i], key, []));
    list = list.concat(findValuesHelper(obj[i], key, []));
    }
    return list;
    }
    @@ -16,7 +16,7 @@ function findValuesHelper(obj, key, list) {
    var children = Object.keys(obj);
    if (children.length > 0){
    for (i = 0; i < children.length; i++ ){
    list = list.concat(getNames(obj[children[i]], key, []));
    list = list.concat(findValuesHelper(obj[children[i]], key, []));
    }
    }
    }
  2. shakhal revised this gist Nov 26, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion find_values.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    function findValues(obj, key){
    return getElementsByTagNameHelper(obj, key, []);
    return findValuesHelper(obj, key, []);
    }

    function findValuesHelper(obj, key, list) {
  3. shakhal created this gist Nov 26, 2014.
    24 changes: 24 additions & 0 deletions find_values.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    function findValues(obj, key){
    return getElementsByTagNameHelper(obj, key, []);
    }

    function findValuesHelper(obj, key, list) {
    if (!obj) return list;
    if (obj instanceof Array) {
    for (var i in obj) {
    list = list.concat(getNames(obj[i], key, []));
    }
    return list;
    }
    if (obj[key]) list.push(obj[key]);

    if ((typeof obj == "object") && (obj !== null) ){
    var children = Object.keys(obj);
    if (children.length > 0){
    for (i = 0; i < children.length; i++ ){
    list = list.concat(getNames(obj[children[i]], key, []));
    }
    }
    }
    return list;
    }