Tips for avoiding line breaks in Zapier workflows while working with JavaScript

Hi there, this is my first time posting on StackOverflow so I appreciate your understanding. Here is the problem I'm facing:

I have a Zap that retrieves data from a Google sheet and adds it to a JavaScript array in a document. I utilized Zapier code to create the array items. I tried two different approaches to achieve this, but encountered the same issue.

1st method: I attempted to push Zap data into a new array to modify the way it's written using the following code snippet:

/* inputData represents the array where Zapier stores your data when using Zap code
it appears like this: inputData = {com1: 'company name 1', com2: 'company name 2'}*/

var newArray = [];
var size = Object.keys(inputData).length;
console.log(size);
for (var i = 0; i < size ; i++ ){
    
    if (inputData['com' + i] != null && inputData['com' + i] != ''){
        newArray.push('\"' + inputData['com' + i] + '\" ');
    } else {
    }
}
var output = {company: newArray};

/* The objective here is to format the new array as follows: output = ["company name 1", "company name 2", etc]

2nd method: involved simply taking the data and utilizing it in the final step of the Zap.

BOTH methods worked fine from a syntax perspective, however, some newline issue disrupted the functionality in the end product.

The result of the array:

View the outcome of the Zap

This is how it appears in the final product, and removing the new lines resolves the issue. I'm unsure how to resolve these new line problems or find a workaround.

company: {com0: 'company name 1
',com1: 'company name 2  //this is the issue, 
',com2: 'company name 4
',com3: 'company name 4
',com4: 'company name 5
'},

Answer №1

After some investigation, I discovered the solution. It turns out that there is an extra invisible new line in the data retrieved from Google Sheet. To resolve this issue, I utilized string.trim() and it effectively resolved the problem.

var newArray = [];
var size = Object.keys(inputData).length;
console.log(size);
for (var i = 0; i < size ; i++ ){
    
    if (inputData['com' + i] != null && inputData['com' + i] != ''){
        var line = inputData[i];
        newArray.push('\"' + line.trim() + '\" ');
    }else{
    }
}
var output = {company: newArray};

It's important to note that this solution can be beneficial for anyone utilizing Zapier to extract data from Google Sheets into a JavaScript document.

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

The result should display the top 5 application names based on the count property found within the ImageDetails object

data = { "ImageDetails": [ { "application": "unknownApp, "count": 107757, }, { "application": "app6", "count": 1900, }, { & ...

jQuery Draggable Slider Scale

Seeking a draggable ruler (meaning it scrolls on double click) similar to the one showcased in the following link: I would greatly appreciate any assistance in finding a library that can provide this same functionality. View image here: https://i.sstatic ...

Retrieve information from a database using PHP and assign it to a JavaScript variable

I need to display a Google map marker on my website, with the latitude and longitude values coming from the database in the columns labeled latitude and longitude. Here is the initial JavaScript code: var map; function initialize() { map = new GMaps( ...

Error: The API call response could not be shown on the webpage

Upon exploring the React App.js page, I discovered that I am making calls to a Django Rest API and receiving an array as a response. Within this array, there are nested components that should be listed in my code. However, when attempting to display multi ...

Issue with formik onchange event not filling data in Material UI TEXTFIELD component

Greetings! I am currently working on a React project where I am managing the authentication process. I am using Material UI and Formik for validation and handling input changes. However, I encountered an issue with my onchange Formik handler in the TEXTF ...

retrieve the value of an HTML element once it has been modified

When I am working in a view, I encounter an issue where I need to retrieve the value of an HTML input box after it has been changed. Initially, the page loads with the following code: <input id="input_one" type="text" value = "apple" /> Upon loadin ...

Is there a way to determine if the bot is being pinged?

I need help creating a new command for my bot that simulates "killing" people. I want the bot to respond with the message "Ha! You thought! @Author died!" if someone pings the bot. (How can I make the Bot detect when it is pinged?) This answer has been u ...

Configuring CORS in an Angular JS controller

Having a controller with a service that retrieves JSON from another server, I encountered the following issue: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http:somesite.com. This can be fixed by moving the ...

What is the best way to determine the size of this array?

Incorporating IMidiQueue for queuing and adding IMidiMsg objects to my IMidiQueue mMIDICreated; There are occasions when I need to determine the total number of items added. I attempted this approach: char buffer[50]; sprintf(buffer, "size %d\n", si ...

What could be causing the issue with my if statement not functioning properly in JavaScript when interacting with a select box?

I'm having some trouble with my code where I am attempting to create a function that retrieves the value of a select box and adds 1 to it. However, I keep encountering errors in my code. Can someone please assist me? Essentially, I just want to increm ...

Manipulating CSS animations through JQuery

Currently, my animation is triggered by a :hover event. However, I would like to change it so that the animation starts when a button is clicked. Can someone guide me on how to manipulate the CSS using JQuery? //CSS .mouth{ top: 268px; left: 273px; ...

Angular JS - Sorting with ng-repeat

I'm completely new to AngularJS and facing a filtering issue with a custom function. My goal is to have: Checkboxes for product categories Checkboxes for product sub-categories A showcase of products When a user clicks on a category, the sub-catego ...

Solution: Resolve clientY scrolling issue within an HTML document

I am facing an issue with the positioning of my context menu. When I right-click and scroll down, the menu does not maintain its regular position. Instead of appearing to the right of the mouse cursor when stationary, it moves below the cursor based on how ...

creating an array of nested structures

Why am I receiving an error message from my compiler stating that there are too many initializer values when I try to initialize this nested structure array? Is there an alternative approach I can take to solve this issue, or could someone please point o ...

Issues with Ionic3 Events functionality

In my Ionic3 app, I utilize events for various functionalities. For example, I employ events to automatically redirect the user to the login screen whenever an API response returns HTTP 401. Thus, within my app.component.ts file, I have the following set ...

The frequent updating of a material's texture map with images at a rapid pace (approximately every 50 milliseconds) results in significant stuttering

Query: What is the most efficient way to swiftly update a sphere's material texture map with images (stored in an HTML5 canvas) at intervals of 50ms to 200ms without causing browser performance issues? I have a collection of panoramic images that nee ...

Manipulating JSON by writing a new array and adding data as child elements

I have a JSON that looks like this: var json = [{ "name": "0xcd963fe5b4d9de5380130d6c6b6cfb5d3b903b1f", "parent": "null" }, { "name": "0xe8f84d8ad5850d66bd289ce3199753c35f4cbf40", "parent": "0xcd963fe5b4d9de5380130d6c6b6cfb5d3b903b1f" }, { "name ...

Guide to adding customized CSS and JavaScript to a specific CMS page on Magento

I'm trying to incorporate a lightbox for video playback on a specific page of my CMS. I've placed my CSS file in JS/MY THEME/JQUERY/PLUGIN/VENOBOX/CSS/myfile.css and the JS files in JS/MY THEME/jquery/plugins/venobox/js/myfile.js, but it doesn&ap ...

Ways to shuffle cells contents within an array

In its current state, the code is set up to populate a UICollectionView with 25 cells by pulling data from the array "cellArray." My goal is to randomize the data without repetition. Right now, there are only 25 elements in the array, but more will be adde ...

Utilizing Functions from Another Component in Angular 2

Picture a scenario where we have 3 components, and one of them contains a function that I need to access in the other components. These components are all at the same level (siblings). file1.ts export class ComponentWithFunction() { function getData() ...