Currently, I am working on extracting a single value from a URL String that contains three variables. The code snippet I am using for this task is as follows:
var hash_array = location.hash.substring(1).split('&');
var hash_key_val = new Array(hash_array.length);
for (var i = 0; i < hash_array.length; i++) {
hash_key_val[i] = hash_array[i].split('=');
var array = hash_key_val[i];
console.log(array);
}
While this code successfully extracts the hash, it separates each item and its corresponding value into different arrays like below:
["object1", "value1"]
["object2", "value2"]
["object3", "value3"]
To obtain only the value, I modified the array to
var x = JSON.stringify(array[1]);
Even though this modification allows me to get the value, I actually only need the first value. However, the current code still returns:
"value1"
"value2"
"value3"
I am looking for suggestions on how I can tweak the code so that it outputs just value1
.
Appreciate any help!