ghardin137
ghardin137•4y ago

Array Iteration

well you'd have to have a valid array. but you only want the info value? or you want anything in that place?
21 Replies
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
ghardin137
ghardin137OP•4y ago
well i'd need to see a valid structure to even remotely guess 🙂
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
ghardin137
ghardin137OP•4y ago
ok so you have an array and what are you wanting to get out of the array?
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
ghardin137
ghardin137OP•4y ago
so you could have multiple objects in this outermost array with a time key? and specifically the string "time"?
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
ghardin137
ghardin137OP•4y ago
ok, so after that you want an array of all of the objects with a location key? are there only locations inside that array?
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
ghardin137
ghardin137OP•4y ago
and you want a single array of just the items that are inside a "time" key?
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
ghardin137
ghardin137OP•4y ago
ok, that's less simple but still doable going to take 3 steps rather than 2
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
ghardin137
ghardin137OP•4y ago
so wait. the "time" string isn't actually the string "time" it's some other string?
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
ghardin137
ghardin137OP•4y ago
ok that's why i asked
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
ghardin137
ghardin137OP•4y ago
const times = array.filter(item => item.hasOwnProperty(varHoldingTimeString));
const locations = times.flatMap(item => item[varHoldingTimeString]);
const location = locations.find(location => location.hasOwnProperty(varHoldingLocationString));
const times = array.filter(item => item.hasOwnProperty(varHoldingTimeString));
const locations = times.flatMap(item => item[varHoldingTimeString]);
const location = locations.find(location => location.hasOwnProperty(varHoldingLocationString));
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View
ghardin137
ghardin137OP•4y ago
it's whatever specifies the "time" you want to match
Unknown User
Unknown User•4y ago
Message Not Public
Sign In & Join Server To View