ここ何日もjavascriptのArrayの更新について考えていましたが・・・結末は簡単だった
removeして、追加しなおしとか考えていましたが。
まじかい。whereでは、参照が返ってくるのか。知らなかったっすwww
node > var __ = require('lodash'); undefined > var a = [{name: 'dokechin'}]; undefined > var match = __.where(a, { name : "dokechin" }); undefined > match [ { name: 'dokechin' } ] > match[0].name = "hogetin"; 'hogetin' > a [ { name: 'hogetin' } ]
配列の中の配列の更新だってお手の物
node > var __ = require('lodash'); undefined > var a = [{name: "dokechin",items : [{name: "pc"},{name : "watch"}]}]; undefined > var match = __.where(a, { name : "dokechin" }); undefined > var matcheditem = __.where(match[0].items , {name : "pc"}); undefined > matcheditem[0].name = "tablet"; 'tablet' > a[0].items[0] { name: 'tablet' }
配列の最後の要素の更新
> var __ = require('lodash'); > var a = [ {name : "dakechin"},{name : "dokechin"}]; undefined > var l = __.last(a); undefined > l { name: 'dokechin' } > l.name = "happy"; 'happy' > a [ { name: 'dakechin' }, { name: 'happy' } ]