Skip to content

Commit 42956d3

Browse files
author
Scott Switzer
committed
swap key_arr and data in preparation for referencing key_arr by index rather than using Array functions
1 parent dadfd1d commit 42956d3

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

src/object-mapper.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,19 +241,22 @@ function setKeyValue(obj,key_str,data)
241241
{
242242
global.elapsed['setKeyValue'].n++ // performance monitoring
243243

244-
// String
244+
// Key_str is written as a simple string
245+
if (typeof(key_str) == 'string')
246+
return update(obj, data, parse(key_str))
247+
248+
// Key_str is an array of values
245249
if (Array.isArray(key_str)) {
246-
key_str.forEach(function(k) {
247-
obj = update(obj, parse(k), data)
248-
})
250+
for (var i=0, len = key_str.length; i < len; i++) {
251+
obj = update(obj, data, parse(key_str[i]))
252+
}
249253
return obj
250254
}
255+
251256
// Key_str is written in object notation form
252257
if (typeof(key_str) == 'object')
253258
return update(obj, data, parse(key_str.key))
254-
// Key_str is written as a simple string
255-
if (typeof(key_str) == 'string')
256-
return update(obj, data, parse(key_str))
259+
257260
// Nothing else is valid
258261
}
259262

0 commit comments

Comments
 (0)