The issue arises when attempting to use the search feature in Ionic because friend.toLowerCase is not a valid function

I keep encountering an error message that says "friend.toLowerCase" is not a function when I use Ionic's search function. The unique aspect of my program is that instead of just a list of JSON items, I have a list with 5 properties per item, such as friend.name, friend.status, and so on. I made some modifications like changing Ionics list to items and mine to friendsList. I suspect the error might be due to naming confusion, but I haven't been able to pinpoint the mistake.

HTML

<ion-searchbar (ionInput)="getFriends($event)"</ion-searchbar>
...
<ion-item *ngFor="let friend of friendsList">
...
<h2>{{friend.name}}</h2>
...

TS

 export class RankfriendsPage {
      friendsList;

     constructor(public navCtrl: NavController, public navParams: NavParams) {
       this.initializefriendsList();
  }

  initializefriendsList() {
    this.friendsList = [
     {
          "name": "Alice",        //list example
          "status": "Online",
          "img": "img/6.jpeg",
          "img2": "img/33.jpeg",
          "text": "+ADD"
        },
    ];

      }




       getFriends(ev) {
          // Reset items back to all of the items
          this.initializefriendsList();

          // set val to the value of the ev target
          var val = ev.target.value;

          // if the value is an empty string don't filter the items
          if (val && val.trim() != '') {
            this.friendsList = this.friendsList.filter((friend) => {
              return (friend.toLowerCase().indexOf(val.toLowerCase()) > -1);
            })
          }
        }

Answer №1

The problem arises from the absence of a friend object that possesses the function toLowerCase(). It appears that you require,

 this.friendsList = this.friendsList.filter((friend) => {
    return (friend.name.toLowerCase().indexOf(val.toLowerCase()) > -1);
 })

Answer №2

friend = {
  "name": "Bob",
  "status": "Offline",
  "img": "img/8.jpeg",
  "img2": "img/57.jpeg",
  "text": "+ADD"
}

It is noticeable that there is no toUpperCase property included in the object.

Should you require it, apply it to a string like friend.name.

Answer №3

Pal is considered an object and objects do not possess the toLowerCase() method.

The toLowerCase() method can only be applied to strings.

You may utilize friend.status.toLowerCase(), friend.name.toLowerCase(), etc.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transferring JSON data between two .NET REST APIs

Due to certain circumstances I won't elaborate on, we are working with 2 .NET Web APIs (A and B). A website sends JSON data to A via jQuery's .ajax() method, and then A needs to forward it to B. Within A, I have a model being passed as a paramet ...

The jQuery $.getJSON function encountered an error and was unable to load the resource, displaying the message "Failed to

I'm encountering a challenge while trying to load a JSON resource from a local Rails application using jQuery 1.4.4. The JSON is confirmed to be valid (verified using jsonlint.com) and I am able to successfully download it when requesting it from oth ...

Transmitting encoded bytes data via JSON

Currently, I am developing a Python RESTful API and facing the challenge of transmitting bytes-encoded data (specifically encrypted data using a public RSA key from the rsa package) over the network in JSON format. This is what the scenario looks like: & ...

Having trouble making API calls in an Angular application

When attempting to call the api using the httpClient method, I encountered an issue where the result was returning as undefined. Below is the code from the services file. contact-service.services.ts import { Injectable } from '@angular/core'; ...

A guide on organizing an Array of Dictionaries into separate columns within clickHouse

To extract data from Kafka and store it in ClickHouse using the Kafka Engine, you can create a table as shown in this example: . CREATE TABLE json(name String, data Array(Map(String, String)) ) ENGINE = Memory; INSERT INTO JSON FORMAT JSONEachRow {"n ...

What methods are most effective when utilizing imports to bring in components?

Efficiency in Component Imports --Today, let's delve into the topic of efficiency when importing components. Let's compare 2 methods of importing components: Method 1: import { Accordion, Button, Modal } from 'react-bootstrap'; Meth ...

Distinguishing between branch and tag within the scope of the package.json dependency

My current setup involves using a Github repository as a dependency in my package.json file with the following format: "dependencies": { "name": "https://github.com/user/repo.git#branch" } However, I am now interested in specifying the v1.4.0 tag from ...

Transforming the "[myObject][1][application]" string into a valid path for a JObject

Let's begin by illustrating what I aim to achieve with pseudo code (even though this example is not feasible). var route = "[Info][Category]"; var document = callToDatabase(); var specificValue = document[route]; I am looking to transform a string i ...

How can I use a string from an array as a key in an object using TypeScript?

I have been utilizing a for loop to extract strings from an array, with the intention of using these strings as object keys. Although this code successfully runs, TypeScript raises a complaint: const arr = ['one', 'two']; const map = ...

What is the best way to transform my tuple so that it can be properly formatted for JSON in Python?

I have a Python code snippet that looks like this: @app.route('/getData', methods = ['GET']) def get_Data(): c.execute("SELECT abstract,category,date,url from Data") data = c.fetchall() resp = jsonify(data) resp.st ...

I would like to check if a given username and password exist in my JSON data

Trying different methods but not achieving the desired outcome. I have limited knowledge about JSON, gathered some information from online sources. var loginDataList = [{ "username": "abc", "password": "abc123" }, { "username": "richa", "p ...

What is the best way to ensure that a class instance only receives the necessary properties?

In my code, I have a function that takes in an object called DataObject and uses certain properties from it to create instances of a class. To determine which data object items should be assigned to which class properties, I use mappings in the form of a ...

For each JSON object, verify whether the value exceeds zero

How can I iterate through each Json result and check if any of the objects (Stage2) have a value greater than 0, then append it to a div? function service(){ var service_id=document.getElementById('down').value; $.ajax({ &a ...

Is there a way to replace mat-button-toggle with a radio button?

Hey there, I am just starting with Angular and I'm looking to transform the code below into radio buttons. <div class="col-4"> <div class="label-icon"><label><b>Certfication Required</b></label> </div&g ...

Learn how Angular 2 allows you to easily add multiple classes using the [class.className] binding

One way to add a single class is by using this syntax: [class.loading-state]="loading" But what if you want to add multiple classes? For example, if loading is true, you want to add the classes "loading-state" and "my-class". Is there a way to achieve t ...

Storing unprocessed JSON data as a string within the database

Is there a way to store Raw JSON data as a String in an MsSql database using a POST request with Jackson ObjectMapper for conversion, but faced with difficulties converting raw JSON into a string? { "id": 1, "someName":"someName", "json": { ...

What is the functionality of ngModel in the Angular Heroes Tour tutorial?

Hello everyone, this is my first post here. I have been diving into the Angular Tour of Heroes using Angular 6 and I think I understand how ngModel works, but there's one thing that puzzles me. How does it manage to update the data in my list when th ...

Strategies for transferring data from index.html to component.ts in Angular 4

Greetings, as a newcomer to Angular, I am seeking advice on how to link my Index.html file to component.ts. Please review the code snippet below where I have created a function called scannerOutput in my Angular index.html file which is functioning properl ...

Fill the table with information from a JSON file by selecting options from drop-down menus

I am currently working on a web application project that involves bus timetables. My goal is to display the timetable data in a table using dropdown menus populated with JSON information. While I believe I have tackled the JSON aspect correctly, I am facin ...

Ensure the forkjoin operation completes before proceeding with the following code

Seeking assistance with a behavior that I am uncertain about. The issue I am facing is that the clients.forEach() function is throwing an error in my code snippet below. I suspect this is happening because it runs simultaneously with the forkJoin(). As a ...