JavaScript indexOf, lastIndexOf Methods Tutorial - Google Sheets Apps Scripts - Array Methods Part 6

preview_player
Показать описание
In this tutorial learn how to use indexOf & lastIndexOf array methods in JavaScript. This tutorial also covers specific challenges related to Google Sheets Apps Scripts and indexOf method.

Link do data used

Array Methods Series Part 5

#javascript #indexof #lastindexof #array
Рекомендации по теме
Комментарии
Автор

As well as the indexOf method, I learned how to convert a 2-dimensional array into a 1-dimensional one, which I had never done before. Congratulations, very useful stuff.

diegomouratorres
Автор

You are the guy who makes me understand AppScript easily.
Requesting more videos on appScript

kowsergazi
Автор

I would like to be able to make the reading of a table with row and columns that is traversed to the end of the last row. I have used a for loop but I know the row total, my idea is not to worry about the row total especially if there are a large number of records. I appreciate your help. The channel is great

ESP
Автор

Looking forward to seeing how you would capture all matches, not just the first or last.

AndrewMalcolmson
Автор

How would find the row(s) which mentions today's date in the sheet? Given that you have today's date as string stored in a variable. This is especially useful when you dates/events stored in a sheet and you like to display the row associated with today on a website (not using Google Calendar).

mj-yyri
Автор

hi there! your videos have been helping a lot! great job on the videos...

I have one question though >> will the indexOf result be affected when the values you are searching for is from query function result??

khairulanwarjohari
Автор

Thank for the video. Would appreciate if you could share how to indexOf dates?

jooling
Автор

I'm having trouble with IndexOff with dates. I want to find the index in a column of dates that match a given date. I know I have to convert the date to something, but don't know how. A little help would be appreciated.

BLTT
Автор

Thank you very much for these brilliant series.
How to set format Date, sometime I get dd/mm/yy, sometime mm/dd/yyyy tks

luusydney
Автор

this is really a good tutorial. Thanks, What about mapping the 1D Array back to 2D Array to append the column? what would be the map function look like?

printcenter
Автор

Thanks for the vid,
How would you reference the row(or column )number found by the function?
For example (this is what I've been trying):

var rownumber = newdata.indexOf("8864-175W")

itatgavins
Автор

The getvalues() function changed for V8. The results returned shown in this video for getvalues() are wrong - it now returns a 2D array where each cell is an array... so getvalues now returns [[id], [sales_rep], [sales], [location]], which is NOT what is shown here, and consequently, the indexof function breaks. Any suggestions? The only one I've found is to map a simple function to extract each cell into a 1D array, and then run the indexOf function on it. Any other ideas?

i.am.glenpayne
Автор

Hi - I am literally copy and pasting from the array to make sure what I am searching for is in there, and it still returns -1. Am I missing something?

var int = dates[0].indexOf("Date:");
Logger.log(int);

maxieearle
Автор

Could I use this in an onEdit? I'm still learning but for some reason it's not working. I want it to find the cell then activate it.

function onEdit(e) {

var range = e.range;
var spreadSheet = e.source;
var sheetName =
var column = range.getColumn();
var row = range.getRow();
var lastRow = sheetName.getLastRow();
var data = activeSheet.getRange(3, 2, lastRow, 1).getValues();
var newData = data.map(function(r){ return r[0]; });

if (sheetName == 'Stocks' && column == 2 && row == 2)
{

sheetName.getRange(newData.indexOf(searchFor)+3, 2).activate();
}

}

Looking for the change to happen in "B2" then find the value in "B3:B140" then activate the cell.

JoeSalmi
Автор

Which part of this tutorial talk about switch?

ezrapetra
Автор

Its's Great Tuto. and learning.
I'm seraching a solution to do a sort of Vlookuup function in Javascript...
I have an tab in a sheet with description, name, and item code
I would like to add a new column to this tab with the sales values, but without a Formula, with a script to avoid any re-calculation or dynamic update.

What I did is to take the 80 000 line in a array with an additional column for this data
And for each item code, so each line of the origin array find the index of the same item code in sales array
and put the data in the row of the array
then setvalues back on the gsheet

this is sometoimes very long and I would like to understand or see if there is no faster or more efficient method to build one array by a matching key of 2 different arrays

arthurlegrandG
join shbcf.ru