I've the following snippet, which must return objects by some condition, but I got this error: Uncaught TypeError: Cannot read property 'obj1' of undefined
. However, I see this data attr in the li
object using console.
for(var i = 0; i < 15; i++){
li = $('<li>List</li>');
$(li).data('test', {obj1: (i < 10 ? 'some' : 'any')});
$(li).appendTo('#list');
}
var f = $('#list li').filter(() => {
return $(this).data('test').obj1 == 'any'
});
console.log($(f));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id ="list">
</ul>