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 Overflow
🌐
Codecademy
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 ...
🌐
Rollbar
rollbar.com › home › how to fix typeerror: cannot read property length of undefined in javascript
How to Fix TypeError: Cannot Read Property Length of Undefined in JavaScript
July 13, 2025 - When you see TypeError: Cannot read property 'length' of undefined, JavaScript is telling you that you're trying to access the length property on something 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
🌐
TrackJS
trackjs.com › javascript answers › how to fix `cannot read properties of undefined (reading 'length')`
How to fix `Cannot read properties of undefined (reading 'length')` • TrackJS
June 19, 2025 - Common JavaScript error when accessing length property on undefined values. Usually occurs with arrays, strings, or API responses that haven't loaded yet. Quick fixes: add null checks, use optional chaining, handle loading states.
🌐
Medium
codehome.medium.com › how-do-i-check-for-an-empty-undefined-null-string-in-javascript-b4a9507742b4
How do I check for an empty/undefined/null string in JavaScript? | by Programise | Medium
January 16, 2023 - let str = ""; if(str.length === 0) { console.log("String is empty"); } 2. To check for an undefined variable, you can use the typeof operator.
Find elsewhere
🌐
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...
🌐
Tim Mousk
timmousk.com › blog › javascript-string-length
How to find the length of a string in JavaScript? – Tim Mouskhelichvili
March 11, 2023 - If the string is empty, this property will return 0. This is a read-only property. All major browsers support the length property 🥳. It is an ECMAScript1 feature (1997). Here is a small example of the length property in action: javascriptconst ...
🌐
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
🌐
Flexiple
flexiple.com › javascript › javascript-string-length
JavaScript String Length property explained | Flexiple Tutorials | JavaScript - Flexiple
March 11, 2022 - For the few of you who are curious how UTF-16 works you can use this link to read more. Apart from this, in case you haven’t already figured it out - The JavaScript string length would return 0 when invoked on an empty string.
🌐
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
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-string-length
JavaScript string.length | GeeksforGeeks
November 16, 2024 - Return Values: It returns the length of the given string. In JavaScript arrays also have length property to find length of an array.
🌐
PHP
php.net › manual › en › function.strlen.php
PHP: strlen - Manual
Thus, PHP's strlen function can be used to find the number of bytes in a binary string (for example, binary data returned by base64_decode). ... When checking for length to make sure a value will fit in a database field, be mindful of using the right function.