Skip to content

farhanacsebd/string-array-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 

Repository files navigation

js-string-array

case-convert:

Forces all parameters to be toUpperCase() and toLowerCase()

const userInput = 'blackPinK';
const namePro ='blackpink';
// console.log(namePro.toUpperCase());
if(userInput.toUpperCase() == namePro.toUpperCase()){
    console.log('user exists');
}

Apply Search includes, indexOf, startswith, endswith

  • indexOf or includes are both the same type function.
  • startswith see only the starting product name.
  • endswith see only last of the product search name.
const products =[
    'Dell hardcore i29 200GB processor laptop',
    'iPhone 1TB camera Phone',
    'yellow laptop with black camera',
    '1X59 Lenova cammercial yopa laptop',
    'purpel color phone with LapTop',
    'LG supernova laptop',
    'Lava smart phone',
    'corei7 laptop',
    'Grammin Phone'
]

const search = 'laptop';

const output =[];

// indexOf
for(const product of products){
   if(product.toLowerCase().indexOf(search.toLowerCase())!=-1){
    output.push(product);
   }
}
console.log(output);

includes

const products =[
    'Dell hardcore i29 200GB processor laptop',
    'iPhone 1TB camera Phone',
    'yellow laptop with black camera',
    '1X59 Lenova cammercial yopa laptop',
    'purpel color phone with LapTop',
    'LG supernova laptop',
    'Lava smart phone',
    'corei7 laptop',
    'Grammin Phone'
]

const search = 'Phone';

const output =[];

// includes
for(const product of products){
    if(product.toLowerCase().includes(search.toLowerCase())){
        output.push(product)
    }
}
console.log(output);

startsWith

const products =[
    'Dell hardcore i29 200GB processor laptop',
    'iPhone 1TB camera Phone',
    'yellow laptop with black camera',
    '1X59 Lenova cammercial yopa laptop',
    'purpel color phone with LapTop',
    'LG supernova laptop',
    'Lava smart phone',
    'corei7 laptop',
    'Grammin Phone'
]

const search = 'dell';

const output =[];

// startsWith
for(const product of products){
    if(product.toLowerCase().startsWith(search.toLowerCase())){
        output.push(product)
    }
}
console.log(output);

endsWith

const products =[
    'Dell hardcore i29 200GB processor laptop',
    'iPhone 1TB camera Phone',
    'yellow laptop with black camera',
    '1X59 Lenova cammercial yopa laptop',
    'purpel color phone with LapTop',
    'LG supernova laptop',
    'Lava smart phone',
    'corei7 laptop',
    'Grammin Phone'
]

const search = 'dell';

const output =[];

// endsWith
for(const product of products){
    if(product.toLowerCase().endsWith(search.toLowerCase())){
        output.push(product)
    }
}
console.log(output);

How to split, slice, substr, substring, concat, join:

  • Splits a string into an array of smaller substrings.
const anthum = 'Amar Sonar Bangla Ami Tomake Valobashi';
// split
const words=anthum.split(' ');
console.log(words)
  • Slice Extracts a small portion of a string and returns it.
const anthum = 'Amar Sonar Bangla Ami Tomake Valobashi';
// slice
const smallSlice = anthum.slice(2,10)
console.log(smallSlice);
  • It will return as many calls starting from a position.
const anthum = 'Amar Sonar Bangla Ami Tomake Valobashi';
// substr
const anotherPart = anthum.substr(2,10)
console.log(anotherPart);

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy