How to get item array from a array of object by writing function? [duplicate]

I have a array like this-

[
 {
   title: "The Soundbox"
   descrption: "this is description"
   rating: "5"
 },
 {
   title: "The Soundbox2"
   descrption: "this is description"
   rating: "5"
 },
 {
   title: "The Soundbox3"
   descrption: "this is description"
   rating: "5"
 }
]

Now to have to write one funcion for getting this-

["The Soundbox", "The Soundbox2", "The Soundbox3"] // Here you can see the title only

Please help me to getting this.

Trying to figure out a way to search a JSON file received from ninox API

I’m a junior in college so i’m not fully experienced in coding just yet; However recently I got an internship and I was assigned a task to create a website that connects to the ninox database. So far i’ve been able to properly connect to the API endpoints and receive the JSON that contains all of the records stored in a specific database. Now i’m trying to work on a function that searches through the JSON file and returns values that match what was in the search box. Looking online for a solution I was able to find functions that use the JQuery RegEx() function but i’m not exactly sure how to implement that,and also i’m trying to store the JSON data into a variable and i’m not sure if its formatted correctly. Heres my current code:

//current fucntion
function search(){
//gets value from search bar. not sure if this even needs to be used if regEx is used.
let sName = document.getElementById(‘searchBar’).value;
var entry;
sName = sName.toUpperCase();

//connects to API endpoint
var request2 = new XMLHttpRequest();
var accessToken = 'my token is here';
request2.open('GET','my URL is here');
request2.setRequestHeader('Authorization', 'Bearer ' + accessToken);
//function that stores the JSON reply into a variable
request2.onload = function(){
    // this contains the JSON data
    var data = JSON.parse(this.response)
    if (request2.status >= 200 && request2.status < 400) {
        //this currently just stores JSON data on webpage for testing purposes
        document.getElementById("JSON").innerText += JSON.stringify(data);
    } else {
        alert('error');
    }
}
request2.send();

alert(sName);

}

The JSON it returns is:
JSON

I’m trying to search through both the Title and Synopsis Keys for matching strings. Any ideas that would help me achieve this would be greatly appreciated!

how to use async/await inside promise

I want to use async/await inside this promise.allSettled to convert currency by fetching some api or databased stored currency rates.

like i want to use await here like this, but not sure where to put async.

arrcars["price_client"] = await forexService.convertCurrency(item.regular_price, "EUR", userCurrency);

I have posted my entire code. need some guidance here.

This is controller

    const httpStatus = require('http-status');
    const pick = require('../utils/pick');
    const catchAsync = require('../utils/catchAsync');
    const async = require('async');
    const axios = require('axios');
    const { talixoService } = require('../services');
    const { iwayService } = require('../services');
    const { forexService } = require('../services');
    
        const searchCars = function (req, res) {
            const talixoData = talixoService.findTalixoCars(req.body) //call talixo api in services
            const iwayData = iwayService.findiWayCars(req.body) //call iwaytransfers api in services
        
            if (req.query.usercurrency) {
                var userCurrency = req.query.usercurrency;
            } else {
                var userCurrency = "INR";
            }
        
            return Promise.allSettled([talixoData, iwayData]).then(([restalixo, resiway]) => {
                const taxiresults = [];
                if (restalixo.status === "fulfilled") {
                    //console.log(restalixo.value.data);
                    if (restalixo.value.data.taxis.length) {
                        restalixo.value.data.taxis.forEach(function (item) {
                            arrcars = {};
                            arrcars["carname"] = item.car_model;
                            arrcars["originprice"] = item.regular_price;
                            arrcars["price_client"] = forexService.convertCurrency(item.regular_price, "EUR", userCurrency);
                            arrcars["discountprice_client"] = forexService.convertCurrency(item.discount_price, "EUR", userCurrency);
                            arrcars["packageId"] = item.id;
                            arrcars["image"] = item.image_url;
                            arrcars["freewaittime"] = item.included_waiting_time;
                            arrcars["maxluggage"] = item.luggage;
                            arrcars["maxpassengers"] = item.seats;
                            arrcars["discountprice"] = item.discount_price;
                            arrcars["vehicletype"] = item.vehicle_type;
                            arrcars["vendor"] = "Talixo";
                            arrcars["vehicleremarks"] = "Or Similar";
                            taxiresults.push(arrcars);
                        });
                    }
                    if (restalixo.value.data.limousines.length) {
                        restalixo.value.data.limousines.forEach(function (item) {
                            arrcars = {};
                            arrcars["carname"] = item.car_model;
                            arrcars["originprice"] = item.regular_price;
                            arrcars["price_client"] = forexService.convertCurrency(item.regular_price, "EUR", userCurrency);
                            arrcars["discountprice_client"] = forexService.convertCurrency(item.discount_price, "EUR", userCurrency);
                            arrcars["packageId"] = item.id;
                            arrcars["image"] = item.image_url;
                            arrcars["freewaittime"] = item.included_waiting_time;
                            arrcars["maxluggage"] = item.luggage;
                            arrcars["maxpassengers"] = item.seats;
                            arrcars["discountprice"] = item.discount_price;
                            arrcars["vehicletype"] = item.vehicle_type;
                            arrcars["vendor"] = "Talixo";
                            arrcars["vehicleremarks"] = "Or Similar";
                            taxiresults.push(arrcars);
                        });
                    }
                }
                //iwaytransfers supplier data
                if (resiway.status === "fulfilled") {
                    //console.log(resiway.value.data);
                    if (resiway.value.data.result.length) {
                        resiway.value.data.result.forEach(function (item) {
                            var imgsrc = "https://iwayex.com/images/cars/";
                            arrcars = {};
                            arrcars["carname"] = item.car_class.models[0];
                            arrcars["originprice"] = item.price;
                            arrcars["price_client"] = forexService.convertCurrency(item.price, "EUR", userCurrency);
                            arrcars["discountprice_client"] = forexService.convertCurrency(item.price, "EUR", userCurrency);
                            arrcars["packageId"] = item.price_uid;
                            arrcars["image"] = imgsrc + item.car_class.photo;
                            arrcars["freewaittime"] = item.allowable_time;
                            arrcars["maxluggage"] = "";
                            arrcars["maxpassengers"] = item.car_class.capacity;
                            arrcars["discountprice"] = item.price;
                            arrcars["vehicletype"] = item.vehicle_type;
                            arrcars["vendor"] = "iway Transfers";
                            arrcars["vehicleremarks"] = "Or Similar";
                            taxiresults.push(arrcars);
                        });
                    }
                }
        
                if (taxiresults.length) {
                    sortedresult = taxiresults.sort(function (a, b) {
                        return a.discountprice - b.discountprice;
                    });
                    res.status(200).send(sortedresult)
                }else{
                    res.status(200).send({})
                }
            });
        }

module.exports = {
    searchCars
}

this is inside

forex.service.js

    const convertCurrency = async (amount, basecurrency, reqCurrency) => {
        if (basecurrency === reqCurrency) {
            let result = Math.round(amount) + ' ' + reqCurrency;
            return result;
        } else {
            const reqForexData = await getForexbyISO(reqCurrency);
            const baseForexData = await getForexbyISO(basecurrency);
            const amountInUSD = amount / baseForexData.forexRate;
            const amountInreqC = amountInUSD * reqForexData.forexRate;
            let result = Math.round(amountInreqC) + ' ' + reqCurrency;
            return result;
        }
    }

module.exports = {
    convertCurrency
}

Check for identical values within object

How can I determine if all items in coverages have identical Name properties? The below example should return false as Medical and Dental are not identical.

 let coverages = [
     0: {Name: 'Medical'}, 
     1: {Name: 'Medical'}, 
     2: {Name: 'Dental'}
    ]

How to use javascript to validate Telerik RadDatePicker for invalid dates entered?

I’m using two RadDatePicker controls showing Date From and Date To and need to make sure that before submitting the form, at least one of the date is provided.

I have a JavaScript code checking to make sure that the user provides at least one date value:

function validateDates(sender, eventArgs) {

    var datePicker1 = $find("<%=RadDatePicker1.ClientID %>");
    var datePicker2 = $find("<%=RadDatePicker2.ClientID %>");


    if (datePicker1.get_selectedDate() == null && datePicker2.get_selectedDate() == null) 
    {
        alert("At least one date should be selected");
        eventArgs.set_cancel(true);
    }

       //alert(datePicker1.lastSetTextBoxValue.value);
       //return false;
}

That part works.

However, a user can also type a string in which case, it will also fails with the same message, because get_selecteddate() method also returns null.

But, what I want is to actually check if the value entered is of a date format and display the corresponding message to the user.

So, in my case, I would need to use a validation for the correct date format as well.

I noticed that when Telerik DatePicker is rendered, it builds the following html sections:

<input id="ctl00_Contentplaceholder2_RadDatePicker1_dateInput" name="ctl00$Contentplaceholder2$RadDatePicker1$dateInput" class="riTextBox riError" type="text" style="">

<input id="ctl00_Contentplaceholder2_RadDatePicker1_dateInput_ClientState" name="ctl00_Contentplaceholder2_RadDatePicker1_dateInput_ClientState" type="hidden" autocomplete="off" value="{&quot;enabled&quot;:true,&quot;emptyMessage&quot;:&quot;&quot;,&quot;validationText&quot;:&quot;&quot;,&quot;valueAsString&quot;:&quot;&quot;,&quot;minDateStr&quot;:&quot;1980-01-01-00-00-00&quot;,&quot;maxDateStr&quot;:&quot;2099-12-31-00-00-00&quot;,&quot;lastSetTextBoxValue&quot;:&quot;hhh&quot;}">

From that html I see that when a string is entered into a DatePicker, its input element gets assigned a css class called riError and its lastSetTextBoxValue has a string I entered.

So, I can assume, I can use those two properties to improve my validation logic.

How can I do that? Any ideas?

Vite cacheDir Not being Used for Cached Files

I’m using vite 2.9.13 which is the latest version I believe.

Also still using Vue 2 if that makes a difference here.

When deploying I’m building assets in my Github Actions so as to not need to have node_modules installed on my server.

But this then eliminates the the cache files generated on build, so I’ve set a new cacheDir value in my vite config:

cacheDir: '.deps'

But when I build I get nothing in .deps and nothing in the default node_modules/.vite

Any idea what I need to do to get cache files to build in a different directory?

vue.js – Is there any way to render elements in two different divs using one v-for loop?

The goal is to make the output look like this:

<div id="tabs">
    <div id="first">
        <a>tab 1</a>
        <a>tab 2</a>
    </div>
    <div id="second">
        <a>tab 3</a>
    </div>
</div>

Currently I’m using this solution (using two v-for loops):

tabs.js (current)

export default {
    data() {
        return {
          tabs: {
              first: [{ name: 'tab1' }, { name: 'tab2' }],
              second: [{ name: 'tab3' }],
          }
        }
    }
    template: `
        <div id="tabs">
            <div id="first">
                <a v-for="tab in tabs.first">{{ tab.name }}</a>
            </div>
            <div id="second">
                <a v-for="tab in tabs.second">{{ tab.name }}</a>
            </div>
        </div>
    `
}

I had an idea to do something like this but it performs more iterations than in the case with two loops:

tabs.js (idea)

export default {
    data() {
        return {
          tabs: {
              test: [
                  { name: 'tab1', category: 'first' },
                  { name: 'tab2', category: 'first' }, 
                  { name: 'tab3', category: 'second' }
              ]
          }
        }
    }
    template: `
        <div id="tabs">
            <div v-for='category in ["first", "second"]' :id='category' :key='category'>
                <template v-for="tab in tabs.test">
                    <a v-if="tab.category === category">{{ tab.name }}</a>
                </template>
            </div>
        </div>
    `
}

I read this topic but it contains slightly different solutions, which unfortunately didn’t work in this case.

google drive api – ‘await’ has no effect on this expression

I have seen countless tutorials online with almost identical code to mine simply putting await infront of the google drive call.

Yet any google call i try add ‘await’ infront of i get the error:

'await' has no effect on this type of expression

The code DOES RUN SUCCESSFULLY, but we are getting race conditions because the await is not being respected.

Sample Code

// Initialize a service account with the key file and scope needed.
// Use it for or Google Drive authorization.
const KEYFILEPATH = 'credentials.json';
const SCOPES = ['https://www.googleapis.com/auth/drive'];
const gal = require('google-auth-library');
const { google } = require('googleapis');
const auth = new gal.GoogleAuth({
  keyFile: KEYFILEPATH,
  scopes: SCOPES
});
const drive = google.drive({ version: "v3", auth });


//-------------------------------------------------------------------------------------------------------
//
async function writeFileFromPath(srcPath, dstFolderId, ext, fileName) {

    run().catch(console.error.bind(console));

    async function run() {
        try{



    console.log("Using File Path: ",srcPath);


  if (fileName == '') {
    fileName = srcPath.match(/[w()-.]+.[w]+/g)[0];  // Extract just the filename
  }

  console.log("Using File Name: ",fileName);

  if (ext == '') {
    ext = fileName.match(/[w]+$/g)[0];
  }

  let mimeType = mimeTypes[ext];

  if (mimeType == '') {
    mimeType = 'text/plain';
  }

  console.log("Using MIME Type: ",mimeType);

  let fileMeta = {
    'name': fileName,
    'parents': [dstFolderId]
  };

  let media = {
    mimeType: mimeType,
    body: fs.createReadStream(srcPath)
  };

// This await does not actually work and code runs ignoring it
  let driveResp =  await drive.files.create({
    supportsTeamDrives: true,
    resource: fileMeta,
    media: media,
    fields: 'id'
  });

  //console.log("Write Call Resp: ",driveResp);
  let fileCreated = false;

  if(typeof driveResp.data !== "undefined"){
    if(typeof driveResp.data.id !== "undefined"){
        console.log(`Created file with id: ${driveResp.data.id}`)
        fileCreated = true;
        return({ status: 200, statusText: `Created file with id: ${driveResp.data.id}` });
    }
  }
  if(!fileCreated){
    console.log(`Failed to create file: ${driveResp}`)
    return({ status: 400, statusText: `File was not created: ${driveResp}` });
  }


} catch (e){
    logger.addLog("googleDrive", "alert", "Unhandled Err: " + e);
    console.log("writeFileFromPath Error Caught: ",e.message);
    return(e.message)
}

    }

};

Is there a way to get svg path from svg url?? (not from svg file)

https://codepen.io/Mamboleoo/pen/eYGxEzV?editors=0010

First of all, here is an example of codepen using three.js and svg that I want to implement.
The question has nothing to do with three.js, so you don’t have to look at the example or just look at the question below.

The problem is that in the above example, it appears that the path.getPointAtLength was used directly for the svg path of html.
In my case, it is not an svg file, but I always get a different svg url from API.

It was successful to set the svg url in img.src and display svg img on the canvas.
But, I don’t know how to implement the codepen example above.

I don’t know how to use my svg url for this part…T.T
Please help me…

// Get the Path in the DOM
const path = document.querySelector("path");

// Store the total length of the path const
length = path.getTotalLength();

How to access props from a component that extends another component in React?

I have 3 components:

-Component A
    -Component B
        -Component C extends Component B

I’m passing a function as props from Component A to Component B and want to call the function in Component C.

I’ve tried added:

constructor(props) {
   super(props);
   this.props.validationsFunc = this.props.validationsFunc.bind(this);
}

and variations with/without props on either side of the bind in Component B. But when I try calling this.props.validationsFunc() in Component C, I get the error saying it is not a function

How do I access this function in Component C without directly passing props to it?

Getting an “Uncaught TypeError” while code is working, what’s the problem?

The task was to emulate keyboard buttons using HTML, then using JavaScript add class “active” on keyboard press to the same HTML “button”, then when i press other button, it adds class to the new one and removes from previous.
My code is working as i wanted, but i keep getting this error on every button press:
“Uncaught TypeError: Cannot read properties of undefined (reading ‘toUpperCase’)”

Here’s JS code:

function t11() {

let div = document.querySelectorAll(".board");

for (let i in div) {
    if (event.code == `Key${div[i].textContent.toUpperCase()}`) {
        div[i].classList.add("active");
    } else if (event.code == `Digit${div[i].textContent}`) {
        div[i].classList.add("active");
    } else if (event.code == div[i].textContent) {
        div[i].classList.add("active");
    } else if (div[i].classList.contains("active") && event.key !== div[i].textContent) {
        div[i].classList.remove("active");
    }
}}  document.querySelector(".i-11").onkeydown = t11;

Here’s HTML:

        <div class="task-11">
            <div class="keyboard">
                <div class="board">0</div>
                <div class="board">1</div>
                <div class="board">2</div>
                <div class="board">3</div>
                <div class="board">4</div>
                <div class="board">5</div>
                <div class="board">6</div>
                <div class="board">7</div>
                <div class="board">8</div>
                <div class="board">9</div>
                <br>
                <div class="board">q</div>
                <div class="board">w</div>
                <div class="board">e</div>
                <div class="board">r</div>
                <div class="board">t</div>
                <div class="board">y</div>
                <div class="board">u</div>
                <div class="board">i</div>
                <div class="board">o</div>
                <div class="board">p</div>
                <br>
                <div class="board">ShiftLeft</div>
                <div class="board">AltLeft</div>
                <div class="board">ControlLeft</div>
                <div class="board">Space</div>
                <div class="board">Enter</div>
            </div>
            <input type="text" class="i-11">
            <div class="out-11">
            </div>
        </div>

is there any free web based id card management software?

i am new to development. I need a free web-based id card management software that should offer data collection from schools, colleges and institutions. While logged in.. a school person will type the data of all the students in the software or upload the CSV file, preview the id card model and submit it. That data should be shown in the back end to the shop owner to download individual student or group data(excel or CSV)and sent to print id cards. I appreciate any help you can provide.