By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
rocoderesrocoderes
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Notification Show More
Latest News
How to set the dropdown value by clicking on a table row
Javascript – How to set the dropdown value by clicking on a table row
JavaScript
Attempting to increase the counter, when the object's tag exist
Javascript – Attempting to increase the counter, when the object’s tag exist
JavaScript
Cycle2 JS center active slide
Javascript – Cycle2 JS center active slide
JavaScript
Can import all THREE.js post processing modules as ES6 modules except OutputPass
Javascript – Can import all THREE.js post processing modules as ES6 modules except OutputPass
JavaScript
How to return closest match for an array in Google Sheets Appscript
Javascript – How to return closest match for an array in Google Sheets Appscript
JavaScript
Aa
Aa
rocoderesrocoderes
Search
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Follow US
High Quality Design Resources for Free.
rocoderes > JavaScript > Javascript – How to get elements from an array that do not have certain letter, just using the for loop?
JavaScript

Javascript – How to get elements from an array that do not have certain letter, just using the for loop?

Admin
Last updated: 2024/02/10 at 7:06 AM
Admin
Share
1 Min Read
How to get elements from an array that do not have certain letter, just using the for loop?

Problem:

I need to get the elements from an array that do not have the letter 'l' in them and push it to another array, just using the for loop. For this project no special methods are allowed. I can only use the push() and toLowerCase() methods.

Contents
Problem:Solution:

The result I get is a list of all the names repeated multiple times.

var list =['sage', 'carolina', 'everly', 'carlos', 'frankie'];
var list1 =[];

for(let i in list){
  for(let j in list[i]){
//Get name without the 'l'
    if(list[i][j].toLowerCase() !== 'l'){
      list1.push(list[i]);
    }
  }
}
console.log(list1);

Solution:

A few notes to make:

  1. First check whole word if it contains the letter
  2. Outside that loop, push result so it gets only added once
  3. Better to check it has the letter then the reverse 🙂
var list = ['sage', 'carolina', 'everly', 'carlos', 'frankie'];
var result = [];

for(let i in list){
  var hasL = false;
  // Check every letter
  for(let j in list[i]){
    if(list[i][j].toLowerCase() === 'l') {
      hasL = true;
      break;
    }
   }
  
  // If the condition (hasL) hasn't been met, push to result
  if (!hasL) {
    result.push(list[i]);
  }

}

console.log(result);

Expand snippet

Related

Subscribe to Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Share this Article
Facebook Twitter Email Print
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article How to intercept an eventhandler in javascript? Javascript – How to intercept an eventhandler in javascript?
Next Article how to get prefix values in angular input field Javascript – how to get prefix values in angular input field
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

- Advertisement -

You Might Also Like

How to set the dropdown value by clicking on a table row

Javascript – How to set the dropdown value by clicking on a table row

February 11, 2024
Attempting to increase the counter, when the object's tag exist

Javascript – Attempting to increase the counter, when the object’s tag exist

February 11, 2024
Cycle2 JS center active slide

Javascript – Cycle2 JS center active slide

February 10, 2024
Can import all THREE.js post processing modules as ES6 modules except OutputPass

Javascript – Can import all THREE.js post processing modules as ES6 modules except OutputPass

February 10, 2024
rocoderesrocoderes
Follow US

Copyright © 2022 All Right Reserved By Rocoderes

  • Home
  • About us
  • Contact us
  • Disclaimer
Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc.

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Lost your password?