Reputation: 695
So I was looking through some data and threw in a
console.log(data)
which printed out
List[1]
after drilling down a few times I was able to get to what I wanted but wasn't sure how to log it out...so I have
console.log(data.get(0).get('childItems').get(0).get('nestedItems').get(0).get('name'));
This is extremely long. Is there not a way to drill in with shorter syntax?
Upvotes: 1
Views: 1428
Reputation: 7575
Yes. You can use the .toJS()
method.
So in your case: console.log( data.toJS() )
const obj = Immutable.fromJS( {
name: [ 'a', 'b', 'c' ],
} );
const arr = Immutable.fromJS( [ {
name: [ 'a', 'b', 'c' ],
} ] );
console.log( obj.toJS().name ); // Should return an array
console.log( arr.toJS().name ); // Should return undefined
console.log( arr.toJS()[ 0 ].name ); // Should return an array
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.2/immutable.min.js"></script>
Upvotes: 4