Error in Cordova JavaScript: The method startsWith does not exist in Android

I am encountering an issue with my application on two devices - one running Lollipop and the other running KitKat. The device with Lollipop does not show any errors, but when I try to run my application on it, I receive the following error:

10-13 16:56:56.126: I/chromium(6322): [INFO:CONSOLE(99)] "Uncaught
TypeError: Object ALIM. IL SOLE DI LOPARDO MARIANGELA has no 
method 'startsWith'", source: file:///android_asset/www/soggetti3.html (99)

Below is a snippet of my JavaScript code:

 function onDeviceReady() {

        window.rancolor=ranColor();

        var ricerca=localStorage.getItem('testo_ricerca');
        var risultati = JSON.parse(localStorage["risultati"]);

        var ricerca1=ricerca.toString();
        ricerca1=ricerca1.toUpperCase();
        var res_match=[];

        var lll=risultati.length;

        for(var r=0;r<lll;r++){

            var ppp0=risultati[r][1].toString();
            var ppp1=risultati[r][0].toString();
            var ppp2=risultati[r][2].toString();
            var ppp3=risultati[r][3].toString();

            ppp0=ppp0.toUpperCase();
            alert(ppp0);
            alert(ricerca1);
            var check=ppp0.startsWith(ricerca1);

            if(check==true){
                res_match=res_match.concat([[ppp1,ppp0,ppp2,ppp3]]);
            }

        }
        var y=res_match.length;

Can anyone advise me on how to efficiently search an array of strings to find those that start with a specific string?

Answer №1

To easily incorporate the startWith function into your code, follow the simple steps outlined below:

if (typeof String.prototype.startsWith != 'function') {
  // For an improved implementation, refer to the following snippet
  String.prototype.startsWith = function (str){
    return this.indexOf(str) === 0;
  };
}

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

An ArithmeticException was thrown due to dividing by zero while attempting to compress an image selected from the gallery

I keep encountering the error message java.lang.ArithmeticException: divide by zero as I attempt to compress an image selected from the gallery. Here is the code snippet causing the issue: public String compressImage(String filePath, String outputFilenam ...

'addEventListener' and 'onclick' functions are restricted to the 'window' element and cannot be used on any other element, such as a button

I am currently working on developing a Snakes and Ladders board game using JavaScript. I have encountered an issue with adding 'onclick' or 'addEventListener' events to the buttons in the game. When I try to attach these events to the b ...

Utilizing Mongoose Schema Prehooks in NodeJS Modules

I've recently delved into the world of NodeJS and am currently tackling a tutorial I stumbled upon online for authentication management. You can find the tutorial here: There's a section of code that's tripping me up, and despite scouring t ...

Revamping JSON structure by identifying id references

I recently attempted to update the city name within the JSON object provided below. "City":[ { "Name":"Delhi", "id":"c5d58bef-f1c2-4b7c-a6d7-f64df12321bd", "Towns":[ ...

Utilizing AJAX to amplify the worth of plupload's echo capabilities

Greetings! Here is the JavaScript code I am using for plupload var uploader = new plupload.Uploader({ runtimes : 'html5,flash,silverlight,html4', browse_button : 'pickfiles', // you can pass in id... container: document.getElementById( ...

Angular UI Bootstrap Typeahead - Apply a class when the element is added to the document body

In my current project, I am utilizing angular bootstrap typeahead with multiple instances. Some of these instances are directly appended to the body using the "typeahead-append-to-body" option. Now, I have a specific instance where I need to customize the ...

Looking for a way to prevent anonymous functions in jQuery using Greasemonkey?

Is there a way to prevent the execution of this particular jquery function? I've tried various scripts and even wrote my own, but nothing seems to work. $(document).ready(function () { $(window).on('beforeunload', function() { re ...

Having trouble linking the component to the Redux store

I've been encountering difficulties connecting my CMSForm component to the Redux store. Below are the snippets of code that I have implemented: Reducer: const cmsDefaultState = { cmsNum: "", facilityName: "" }; export default (state = cmsDefault ...

Trouble with mapping an array in my Next JS application

When working on my Next JS app, I encountered an error while trying to map an array for the nav bar. The error message reads: TypeError: _utils_navigation__WEBPACK_IMPORTED_MODULE_6___default(...).map is not a function. Here is the code snippet that trigge ...

jQuery Mobile - Struggling to hide a button with traditional jQuery techniques

Looking for help hiding a simple button? <input type="button" id="logoutBtn" value="logout" data-theme="d" data-inline="true" aria-disabled="false"> Attempted to hide it with this code but it didn't work: $('#logoutBtn').hid ...

Refresh the vuex store values in real-time on the displayed page without the need

I am currently working on displaying variables from my backend that update automatically. To achieve this, I am utilizing Vuex store and nuxt.config.js for transferring the variables. API calls are used to modify the variables in the backend. However, I am ...

Confusion Arises When Joomla Buttons Clash

I am facing an issue with two modules on my website, each containing a button code. The code for the buttons is as follows: First Button <div onclick="parent.location='first-link'" data-mce-onclick=""><button class="button">First Bu ...

Hide the popup of the selectOneMenu when the mouse moves out of it

I am facing a challenge with my PrimeFaces component. I need to find a way to hide the popup of its element when the mouse moves out of it. Unfortunately, adding an onmouseout event directly to the component is not supported by PrimeFaces. <p:selectChe ...

Utilizing additional JavaScript libraries with custom Power BI visuals

Seeking clarification on how to use the d3 library within my visual.ts file. I have installed it using npm and added it to the externalJS section of pbiviz.json, but I am unsure of any additional configurations needed to successfully include and utilize it ...

Instructions for modifying the color of the close button in the angularjs ui-select module

I am currently using ui-select for multiple selection in a dropdown. When an item is selected, it displays a cross button on the upper right corner of the selected item. Is there a way to change the color of the cross button to red? <ui-select multip ...

Creating dynamic JSX content in NextJS/JSX without relying on the use of dangerouslySetInnerHTML

I have a string that goes like "Foo #bar baz #fuzz". I'm looking to create a "Caption" component in NextJS where the hashtags become clickable links. Here's my current approach: import Link from "next/link"; const handleHashTag = str => st ...

When attempting to input a decimal number into a numerical text box, Firefox displays an error message

Here is the code for my numeric input field: <input type="number" id="payment-textbox" name="payment-textbox" min="1" max="100000" maxlength="9" class="payment" placeholder="--" value=""/> While this code functions properly in Google Chrome, I enco ...

Establish and configure an entity

As a beginner, I am looking to organize my dataSet values into an object. Here is how I want to do it: obj: { dataType: _____, //dataSet.getDataType().getName() Value: ______, //dp.getStartTime(TimeUnit.MILLISECONDS)) startTime: ____, ...

Upon logging into the console, the function retrieves the previous value

Within my app's context, I have a state called "operators" that is populated with data when the application initializes. Despite passing this data to a function and selecting a component, I noticed that while the select component displays the correct ...

Server not displaying React Components

Just starting out with React and I'm puzzled why my components won't load. I may have some outdated code lingering around that's causing the issue. Repository URL: https://github.com/04lex/alex-workspace/tree/1da077943681bccba1876165cfd299b ...