Work With Strings in JavaScript II

JavaScript·2 min read·Jan 1, 2026

In JavaScript, string primitives declared as string literals using single quotes '' and double quotes "" are automatically wrapped in the String object, allowing you to use object-specific properties and methods.

Getting the length of strings

To get the number of characters of a string (its length), you can use its length property:

string.length

Example

Let's consider this script, that filters an array based on the length of its string values:

const fruits = [  'banana',  'apple',  'pineapple',  'raspberry',  'orange',  'lemon'];console.log(fruits.filter(fruit => fruit.length <= 5));

When executed, it will use the filter() method of the fruits array to filter out the strings whose length property is greater than or equal to 5 characters.

Unlock the program 🚀

Pay once, own it forever.

€79

30-day money-back guarantee

  • 13 modules
  • 113 lessons with full-code examples
  • 29 projects with commented solutions
  • All future lesson and project updates
  • Lifetime access

By submitting this form, you agree to the Terms & Conditions and Privacy Policy.