The only explanation to length being undefined is if inputData is not a string. You neglected to mention what type of input you're working with, but in any case, casting to string should solve the issue:
function checkInputData() {
$('.mainSearchSubmit').live('click', function () {
var inputData = $(this).parent().children().eq(0).val();
inputData = String(inputData); // Cast to string
console.log(inputData.length);
//this returns undefined
console.log(inputData);
//and this returns text from inpu so i know there is data
});
}
Answer from Hubro on Stack OverflowCodecademy
codecademy.com › forum_questions › 5137597b47c9a9993c007b2a
.length undefined? | Codecademy
What does this mean? TypeError: Cannot read property ‘length’ of undefined What did I do wrong · the console.log will output everything in between your parentheses, so it all needs to be contained in there. Your length should look like this:
Reddit
reddit.com › r/learnjavascript › [deleted by user]
Getting cannot read properties of undefined reading length
July 15, 2022 - Line 208: The condition should be i < array.length -1. Line 209 will lead to the string variable being undefined, hence "length" is an invalid property. Change all your for loops to be the length - 1, to ensure you're not accessing an index that doesn't exist ...
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › length
String: length - JavaScript | MDN
It's the arity of the String function (loosely, the number of formal parameters it has), which is 1. Since length counts code units instead of characters, if you want to get the number of characters, you can first split the string with its iterator, which iterates by characters:
GitHub
github.com › emberjs › ember.js › issues › 11204
String.length returns undefined for empty string in 1.12 · Issue #11204 · emberjs/ember.js
April 10, 2015 - JSBin: http://emberjs.jsbin.com/peposiconi/1/edit?html,js,console,output It seems that in 1.12 accessing the length property of an empty string through a getter returns undefined rather than0. Previously zero was returned as expected. It...
Published May 18, 2015
freeCodeCamp
forum.freecodecamp.org › javascript
TypeError: Cannot read property 'length' of undefined - JavaScript - The freeCodeCamp Forum
December 8, 2020 - ** TypeError: Cannot read property ‘length’ of undefined shows error at if statement at wordsArray[i+1].length why cant length of wordsArray[0+1]= wordsArray[1] cant be read? ** Your code so far function findLongestWordLength(str) { let wordsArray = str.split(' '); let maxWordlength=0; for(var i=0; i wordsArray[i+1].length) { maxWordlength=wordsArray[i].length; }else{ maxWord...
MSR
rajamsr.com › home › javascript string length: 4 easy ways to calculate
JavaScript String Length: 4 Easy Ways to Calculate | MSR - Web Dev Simplified
January 5, 2024 - This code example ensures a default length of 0 is assigned to prevent potential issues when working with undefined string lengths. In JavaScript, the length property of a string does not count the number of Unicode characters but instead counts the number of 16-bit code units (UTF-16 code units).
newspaint
newspaint.wordpress.com › 2013 › 06 › 20 › node-js-string-length-undefined
Node.JS String Length Undefined | newspaint
July 11, 2013 - function writeStringLength( str ) { console.log( "str = \"" + str + "\"" ); console.log( "str.length is " + str.length ); var copy = str; console.log( "copy.length is " + copy.length ); var copyObj = new String( str ); console.log( "copyObj.length is " + copyObj.length ); } var now = new Date(); writeStringLength( now.getFullYear() ); ... user@localhost:/tmp$ /usr/local/node/bin/node /tmp/brokenstring.js str = "2013" str.length is undefined copy.length is undefined copyObj.length is 4 · So – why does JavaScript think the string doesn’t have a defined value for the length property?
W3Schools
w3schools.com › jsref › jsref_length_string.asp
JavaScript String length Property
The length property of an empty string is 0. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, ...
YouTube
youtube.com › junior developer central
Javascript String Length: How to determine the size of a string - YouTube
In this tutorial, we’ll take a look at the JavaScript String Length property and how you can use this to determine the size of a string. Don’t forget to subs...
Published January 31, 2019 Views 3K
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › undefined
undefined - JavaScript | MDN
January 10, 2026 - The undefined global property represents the primitive value undefined. It is one of JavaScript's primitive types.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › length
Array: length - JavaScript | MDN
const numbers = [1, 2, 3, 4, 5]; if (numbers.length > 3) { numbers.length = 3; } console.log(numbers); // [1, 2, 3] console.log(numbers.length); // 3 console.log(numbers[3]); // undefined; the extra elements are deleted
YouTube
youtube.com › watch
How to check the length of a string in JavaScript - Javascript Tutorials for beginners - YouTube
In this tutorial, we'll be looking at various ways to find the length of a string in JavaScript. We'll be looking at both manual methods of finding string le...
Published November 6, 2021