Immutable Lists

Playing with Immutable.js lists

by lau_chung

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.7.2/immutable.min.js"></script>

JavaScript

console.clear();

var oList = [{post_id:53,comment:'old comment 53'},{post_id:54,comment:'old comment 54'}]
var list = Immutable.fromJS(oList);

list = list.update(
  list.findIndex(function(item) { 
    return item.get("post_id") === 53; 
  }), function(item) {
    return item.set("comment", "new comment 53");
  }
); 

alert(list)