Uncaught TypeError: Cannot use 'in' operator to search for 'length' in when getting checked values by data attribute
You're using $.each
on a string
, it needs to be an object
or an array
.
Try changing your code to this
var subjects_names = [];
$.each($("input[name='exam_subjects']:checked"), function () {
subjects_names.push($(this).data("subjectName"));
});
Or better yet use .each
as your iterating over a jQuery objectvar subjects_names = [];
$("input[name='exam_subjects']:checked").each(function () {
subjects_names.push($(this).data("subjectName"));
});
Error : Cannot use 'in' operator to search for 'length' in [{ID:2,Name:EAA2}] when performing $.each
It would seem that "over-stringifying" is an issue with JSON. If I doubled the JSON.parse
or removed the JSON.stringify
it all works correctly.
Annoying!!
Uncaught TypeError: Cannot use 'in' operator to search for 'options' in Mumbai
React Select expects the options to be passed as array of object in this format:
{ value: 'value here', label: 'Label here' }
So, you should be passing locations as an array of objects to options
prop of React-Select select
as:
[
{ label: "Mumbai", value: "Mumbai" },
{ label: "tuljapur", value: "tuljapur" },
....
]
Reference: https://react-select.com/home#getting-startedCode Sandbox link https://codesandbox.io/s/pb4r2s?module=/example.tsx
Cannot use 'in' operator to search for 'length' in... Need to change string?
I think use can use:
$('body').on('click', '#usejson', function() {
//var data = $("#jsonarray").html();
var data = JSON.parse($("#jsonarray").html());
$.each(data, function(i, item) {
alert(data[i].bodypart);
});
});
But i don't understand that why you send json to html and then get it from html. Cannot use 'in' operator to search for 'length' in
It's already a JSON object. You cannot parse it again.
to receive HTTP error code, provide a error callback function next to success
, showed my code below.
function countryPage() { $.ajax({ url: "https://en.wikipedia.org/w/api.php?action=parse&disablelimitreport=true&format=json&prop=text|langlinks&noimages=true&mobileformat=true&page=1&callback=?", contentType: "application/json; charset=utf-8", dataType: "jsonp", success: countryPageSuccess, error: function(jqXHR, textStatus, errorThrown) { alert(jqXHR.status); alert(textStatus); alert(errorThrown); } });}
function countryPageSuccess(data, result) { $.each(data, function(i, item) { console.log(item); });}
countryPage();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Cannot use 'in' operator to search for 'length' in when retrieving data from select
The in
operator only works on objects.
could be the data you are sending needs parsing (i.e a stringified json).
try parsing your data JSON.parse(data)
$.each(JSON.parse(data), function(index, element){...})
Related Topics
Clear JavaScript Console in Google Chrome
Why Doesn't Nodelist Have Foreach
Javascript: Unicode String to Hex
Unexpected Token Illegal in Webkit
Backbone: Why Assign '$('#Footer')' to 'El'
Mocking a Useragent in JavaScript
Using Underscore's "Difference" Method on Arrays of Objects
What Do Double Brackets Mean in JavaScript and How to Access Them
Why Threre Is No Way to Download File Using Ajax Request
What Is the Most Efficient Way to Reverse an Array in JavaScript
How to 'Await' on an Rx Observable
Pass Variables to JavaScript in Expressjs
Sending Binary Data in JavaScript Over Http
How to Handle Oncut, Oncopy, and Onpaste in Jquery
Angular Ui-Router $Urlrouterprovider .When Not Working When I Click <A Ui-Sref="...">
Single Quote Escape in JavaScript Function Parameters
Objects Are Not Valid as a React Child (Found: [Object Promise])