The value located based on the path or the defaule value
TypeError when the iter's [Symbol.iterator] isn't null, undefined or a function, its
[Symbol.iterator]() doesn't return an iterator, the iterator's next() returns a value which is not an object, or
(like for...of) when it stops early (an intervening value is not present) and the iterator's return() doesn't
return an object
let theValue = {
Hello: {
Darkness: {
my: "old"
}
},
friend: "I've",
come: {
to: {
see: "you"
}
}
};
let value = getValueByIter(theValue, ["Hello", "Darkness", "my"], "friend");
// value === "old"
let value = getValueByIter(theValue, ["My", "Old"], "friend");
// value === "friend"
let value = getValueByIter(theValue, ["come", "to"], "friend");
// value === { see: "you" }
let value = getValueByIter(theValue, ["friend"], "friend");
// value === "I've"
Get the named value from the target object where the path is represented by the string iterator or iterable to separate the nested objects of the heirarchy / path to the value. If the target does not contain the full path the iterator will not be completed.
The order of processing of the iterator is not reset if you add or remove elements to the iterator, the actual behavior will depend on the iterator imeplementation.
If the passed and Iterator, like
iteris both an Iterablefor...of(and iterForOf) the iterator returned by its[Symbol.iterator]()is used.The path is read like iterForOf, so on a runtime without
Symbol.iterator(eg. IE) an array, an iterator (or an iterable created by this library) and aMaporSetare read, but a value which is only iterable where there isSymbol.iterator(eg. anargumentsobject) has no keys, so (like an empty path) the target itself is returned. Pass an array (eg. using arrFrom) to use the same path on every runtime.