KodingKaro
JavaScript · Beginner · Strings and Arrays

Working with text and lists

This lesson applies Strings and Arrays concepts to code you can run and adapt.

✓ What you will learn in this topic

  • Explain key Strings and Arrays concepts.
  • Read and adapt the examples.
  • Apply the idea to a small real interface or data task.

Concept explanation

String properties and methods, template literals, array access/mutation, iteration, searching, sorting, and common array methods.

These concepts appear in everyday interfaces and data transformations; understanding the trade-offs helps you choose a reliable implementation.

Syntax

The examples use standard ECMAScript syntax. Run console examples in a browser console or Node.js; DOM examples require a browser page containing the referenced elements.

Example 1: a small experiment

Run this compact example to observe the core rule before applying it to a larger feature.

const city = 'Pune';
console.log(city.toUpperCase() + ' has ' + city.length + ' letters');

Expected output: PUNE has 4 letters

Why it is useful: A small experiment makes the value or behavior easy to inspect.

Example 2: a practical feature

This example models a small piece of application behavior. Adapt its values and inspect what changes.

const tasks = ['Draft', 'Review', 'Publish'];
const openTasks = tasks.filter((task) => task !== 'Publish');
console.log(openTasks.join(', '));

Expected output: Draft, Review

Why it is useful: The same pattern can be extended into a real feature without tying the entire application to one large block of code.

Common mistakes

sort() mutates an array and sorts values as strings by default. Provide a numeric comparator and copy first if needed.

Best practices

Use template literals for interpolation and non-mutating array methods when the original data should remain unchanged.

Practice exercise

Create a searchable product list and sort prices numerically from low to high.

Lesson summary

String properties and methods, template literals, array access/mutation, iteration, searching, sorting, and common array methods.

Knowledge check

Which statement best describes an important idea in Strings and Arrays?

Show explanation

String properties and methods, template literals, array access/mutation, iteration, searching, sorting, and common array methods.

Practical example

javascript
const tasks = ['Draft', 'Review', 'Publish'];
const openTasks = tasks.filter((task) => task !== 'Publish');
console.log(openTasks.join(', '));

Expected result:

Draft, Review

Hands-on practice task

Create a searchable product list and sort prices numerically from low to high.

In this section

Other lessons in Strings and Arrays

Broaden your knowledge

Related learning topics